为什么存在“-i”和“-t” “docker exec”的选项命令? [英] Why do there exist "-i" and "-t" options for the "docker exec" command?
问题描述
docker exec -it ...
, docker exec -i ...
感到困惑和 docker exec -t ...
,所以我决定做一个测试:-
docker exec -it ...
:#docker exec - 它115c89122e72 bash
root @ 115c89122e72:/#ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
正常工作
-
docker exec -i ...
:#docker exec -i 115c89122e72 bash
^ C
该命令挂起,我必须使用 Ctl + c 中断
-
docker exec -t ...
:#docker exec -t 115c89122e72 bash
pre>
root @ 115c89122e72:/#ls
^ C
它成功进入容器,但挂起执行第一个c ommand。
所以,似乎没有必要让$ code> docker exec -i ... 和 docker exec -t ...
命令。任何人都可以详细说明为什么存在 docker exec
-i
和 -t
/ code>命令?
-i
code> - 交互式保持STDIN打开,即使没有附加,如果你想输入任何命令,你需要的。
-t
, - tty
分配伪TTY,一个伪终端,将用户的终端连接到stdin和stdout。 (请参阅 容器/容器。 go
)
如果你做回音,只有 -t
需要。
但是对于输入输入的交互式会话,您需要 -i
。
由于 -i
保持stdin打开,它也用于将输入管道连接到已分离的Docker容器。即使使用 -d
(detach)也可以使用。
请参阅什么时候在Docker容器中使用 - 交互式
而不使用 - tty
:
$ echo hello | docker run -i busybox cat
hello
-i
保持STDIN打开即使不附加,在这种情况下STDOUT的状态是什么?
对于 docker exec
,由 docker运行
。
但是,关于 docker exec
,目前有一个问题(问题8755:Docker tty不是tty与 docker exec
不幸的是,你的发现只相当于在centos6和ubuntu之间的tty的行为:14.04。在exec里面还没有一个功能的tty - 只要做$ code> ls -la / proc / self / fd / 0 ,看到它是一个破坏的链接,指向不存在的
pts
。
我们正在处理的实际错误是某些标准库假定/ proc / self / fds /中的符号链接必须是有效的符号链接
问题是,tty是在主机外部创建的,并且在容器中没有引用它,就像如何在...中设置
/ dev / console
主容器。
解决这个问题的一个选项是分配并将主机中的devpts
绑定到容器中。
To be honest, I have always been confused about docker exec -it …
, docker exec -i …
and docker exec -t …
, so I decide to do a test:
docker exec -it …
:# docker exec -it 115c89122e72 bash root@115c89122e72:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
It works normally.
docker exec -i …
:# docker exec -i 115c89122e72 bash ^C
The command hangs and I have to use Ctl + c to interrupt it.
docker exec -t …
:# docker exec -t 115c89122e72 bash root@115c89122e72:/# ls ^C
It enters the container successfully but hangs on executing the first command.
So it seems there is no point in having the docker exec -i …
and docker exec -t …
commands. Could anyone elaborate on why there exist -i
and -t
options for the docker exec
command?
-i
, --interactive
keeps STDIN open even if not attached, which you need if you want to type any command at all.
-t
, --tty
Allocates a pseudo-TTY, a pseudo terminal which connects a user's "terminal" with stdin and stdout. (See container/container.go
)
If you do an echo, only -t
is needed.
But for an interactive session where you enter inputs, you need -i
.
Since -i
keeps stdin open, it is also used in order to pipe input to a detached docker container. That would work even with -d
(detach).
See "When would I use --interactive
without --tty
in a Docker container?":
$ echo hello | docker run -i busybox cat
hello
-i
keeps STDIN open even if not attached, what is the status of STDOUT in this case?
It is, for docker exec
, the one set by docker run
.
But, regarding docker exec
, there is a current issue (issue 8755: Docker tty is not a tty with docker exec
unfortunately your discovery only amounts to a difference between the behaviour of tty in centos6 vs ubuntu:14.04. There is still not a functional tty inside the exec - just do
ls -la /proc/self/fd/0
and see that it's a broken link pointing to apts
which doesn't exist.the actual bug we're dealing with is that certain standard libraries assume that the symlinks in /proc/self/fds/ must be valid symlinks
The problem is that the tty is created outside on the host and there is no reference to it in the container like how
/dev/console
is setup in the primary container.
One options to fix this would be allocate and bind mount thedevpts
from the host in to the containers.
这篇关于为什么存在“-i”和“-t” “docker exec”的选项命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!