如何从docker中检测bash中的完全交互式shell?
我想在“docker运行”中检测-ti是否已经传递给入口点脚本。
docker run –help for -t -i
-i, --interactive=false Keep STDIN open even if not attached -t, --tty=false Allocate a pseudo-TTY
我已经尝试了以下,但即使在本地testing(不是在docker里面),它不工作,并始终打印出“不互动”。
#!/bin/bash [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
entrypoint.sh:
#!/bin/bash set -e if [ -t 0 ] ; then echo "(interactive shell)" else echo "(not interactive shell)" fi /bin/bash -c "$@"
Dockerfile:
FROM debian:7.8 COPY entrypoint.sh /usr/bin/entrypoint.sh RUN chmod 755 /usr/bin/entrypoint.sh ENTRYPOINT ["/usr/bin/entrypoint.sh"] CMD ["/bin/bash"]
build立形象:
$ docker build -t is_interactive .
交互式地运行图像:
$ docker run -ti --rm is_interactive "/bin/bash" (interactive shell) root@dd7dd9bf3f4e:/$ echo something something root@dd7dd9bf3f4e:/$ echo $HOME /root root@dd7dd9bf3f4e:/$ exit exit
不交互地运行图像:
$ docker run --rm is_interactive "echo \$HOME" (not interactive shell) /root $
这个计算器的答案帮助我find[ -t 0 ]
。
- pipe道docker工运行容器IDdocker执行
- 无法在RUN中运行envvariablesscript.sh Dockerfile
- 希望在docker集装箱中使用多个terminal?
- 在Bashvariables赋值中找不到命令错误
- 如何将几个Python脚本混合到一个shell脚本中?
- 设置像Vim这样的文本编辑器,Spacemacs可以在Docker容器上工作而不需要在主机上安装工具
- 从Docker容器中以不同的用户身份运行命令/脚本
- 提交在/ workspace中生成的文件的容器更改(即使使用makefile)也不会保留到图像的新实例中
- terminal(bash?)/ Docker:背后的逻辑 –