0

Learning Docker, and encountered an interesting scenario. Consider the following sequence of Docker commands. For reference, the docker version in the machine I'm connected at is 20.10.18, build b40c2f6 and I have the latest centos image downloaded.

[cloud_user@eb993010811c ~]$ docker container run -dit --name interactive_centos centos
42afd26322dddeb7878113f9a9a753c09b7c0a43f30d08c04b5a8ac7e9540fcf
[cloud_user@eb993010811c ~]$ docker container run -d --name non_interactive_centos centos
1387f5f8654361d2370e776842560c2e1255a8eb9f5eb9db4fd7bbfcc48aae99
[cloud_user@eb993010811c ~]$ docker container start -ia interactive_centos
[root@42afd26322dd /]# exit
exit
[cloud_user@eb993010811c ~]$ docker container start -ia non_interactive_centos
[cloud_user@eb993010811c ~]$ docker container start -ia non_interactive_centos
[cloud_user@eb993010811c ~]$ echo $?
0
[cloud_user@eb993010811c ~]$ docker container logs non_interactive_centos | tail -n 5
[cloud_user@eb993010811c ~]$ 

We can see that the centos container interactive_centos, which was run with the -dit flags, provides us with a root shell when we start it with the -ia flag. On the other hand, the container non_interactive_centos, which was run from the very same centos image but without the -i and -t flags, does NOT provide us with an interactive TTY when we try to start it with -i and -a flags, and does not even output any logs either at the bash command or the docker logs level.

This is not too surprising, of course, and can be partly explained by a diff on the inspections of these containers:

[cloud_user@eb993010811c ~]$ docker container inspect non_interactive_centos > nic.conf 
[cloud_user@eb993010811c ~]$ docker container inspect interactive_centos > ic.conf 
[cloud_user@eb993010811c ~]$ diff nic.conf ic.conf
.
.
.
142,143c142,143
<             "Tty": false,
<             "OpenStdin": false,
---
>             "Tty": true,
>             "OpenStdin": true,

.
.
.

But my question is: why? If the container is run without the -ia flag, does that mean that as long as that container is alive, no matter how many times it is started, stopped, resumed, an interactive TTY will never be an option? That sounds a bit inflexible as a design choice, but there's probably a reason, and I was wondering what the reason is.

Jason
  • 2,495
  • 4
  • 26
  • 37
  • Fundamentally the answer lies in what start really is: https://stackoverflow.com/questions/34782678/difference-between-running-and-starting-a-docker-container – β.εηοιτ.βε Nov 05 '22 at 18:57

0 Answers0