Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do we have to specify -i when starting an interactive docker container but not the -t?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 -t flag when starting a container, but I have to specify both -i and -t when creating a new container with the run command?

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 -t is 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading