I use docker as part of my education and we start containers with Linux images with the -i flag. Why do I not have to specify the -t flag when starting a container, but I have to specify both -i and -t when creating a new container with the run command?
as in:
docker start -i [container name]
vs
docker run -it ... (rest of the command)
Does a container just permanently have that pseudo-tty when you create it? And will it permanently not have one if the -t is not specified?
>Solution :
Why do I not have to specify the
-tflag when starting a container, but I have to specify both-iand-twhen creating a new container with theruncommand?
First, I would argue that you don’t have to specify -i when creating a container. The -i flag starts the container in interactive mode, but if you don’t need to interact with the container, then not having the -i flag is perfectly fine. You might want to start a web server in a container in the background, and in that case you wouldn’t use -i.
And will it permanently not have one if the
-tis not specified?
Correct. You can see this difference if you try running a program which has special behavior when connected to a tty:
$ docker run -it ubuntu bash
root@b4c828502868:/#
However, if you start it without a tty, it won’t show you a prompt.
$ docker run -i ubuntu bash
You can still type commands (it still has stdin, stdout, and stderr, even without -t) but it won’t act like a normal tty.