文章目录
容器运行时的 -dit 选项
2021-06-22
docker run 命令的选项
--attach , -a Attach to STDIN, STDOUT or STDERR
--detach , -d Run container in background and print container ID
--interactive , -i Keep STDIN open even if not attached
--tty , -t Allocate a pseudo-TTY
docker exec 命令
-d, --detach Detached mode: run command in the background
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY
没有 -a --attach 选项
- -a 可以多次指定 ,比如 -a stdin -a stdout
- 不要同时使用 -t 和 -a stderr,因为 pty 本身的限制。pty
Do not use the -t and -a stderr options together due to limitations in the pty implementation. All stderr in pty mode simply goes to stdout.
使用 bash:lastest 镜像,通过观察 /dev/fd/ 目录,查看容器控制台IO的打开关闭情况。
默认,dit组合是001,前台运行,无法输入,只能看到输出。
只有 -i 没有 -t,容器可以接受stdin的输入,也可以输出,但是通过管道,不是伪终端,是批处理模式,而不是交互模式。
默认:前台运行,stdout 和 stderr 转接出来,而stdin关了
默认 -d=false, -i=false, -t=false
默认 -d=false
-d=false时,默认-i=false,-t=false
dit:000
[work@cdh06 ~]$ docker run --rm bash -c 'ls -l /dev/fd/'
total 0
ls: /dev/fd/3: cannot read link: No such file or directory
lrwx------ 1 root root 64 Jun 22 09:11 0 -> /dev/null
l-wx------ 1 root root 64 Jun 22 09:11 1 -> pipe:[55404435]
l-wx------ 1 root root 64 Jun 22 09:11 2 -> pipe:[55404436]
lr-x------ 1 root root 64 Jun 22 09:11 3
[work@cdh06 ~]$ docker run --rm -d=false bash -c 'ls -l /dev/fd/'
total 0
ls: /dev/fd/3: cannot read link: No such file or directory
lrwx------ 1 root root 64 Jun 22 09:11 0 -> /dev/null
l-wx------ 1 root root 64 Jun 22 09:11 1 -> pipe:[55409027]
l-wx------ 1 root root 64 Jun 22 09:11 2 -> pipe:[55409028]
lr-x------ 1 root root 64 Jun 22 09:11 3
此时,docker 使用了 -a STDERR -a STDOUT 选项。
前台 -t
dit: 001
$ docker run --rm -t bash -c 'ls -l /dev/fd/'
total 0
lrwx------ 1 root root 64 Jun 22 10:14 0 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 22 10:14 1 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 22 10:14 2 -> /dev/pts/0
但是 stdin (/dev/fd/0)是得不到输入的。
前台 -i
dit:010