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. (Seecontainer/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?":It is, for
docker exec
, the one set bydocker run
.But, regarding
docker exec
, there is a current issue (issue 8755: Docker tty is not a tty withdocker exec
Note (Q4 2017): this should been fixed by now (docker 17.06-ce).
See PR 33007.
That PR now allows (since 17.06):
(before 17.06,
tty
was returning "not a tty
")