4

I'm a little confused by some docker flags, and more particularly by the "i", "t" and "it" flags.

First, is "docker run -it" equivalent to "docker run -i -t" ?

Second, what does "Allocate a pseudo-TTY" exactly means (it is the documentation of the "-t" flag) ?

I've conducted a couple of tests with an image (called hello-world) having

CMD ["echo", "Hello docker world !!!"]

or

ENTRYPOINT  ["echo", "Hello docker world !!!"]

The following commands :

  • docker run -i -t hello-world
  • docker run -i hello-world
  • docker run -t hello-world
  • docker run -it hello-world
  • docker run hello-world

all resulted in the display of the text "Hello world". I would expect at least the last one to not display anything...

sr-01-01
  • 87
  • 1
  • 3
  • I think `i` means interactive and `t` means tag. You can use multiple one letter parameters with a single dash in together therefore `-it` should be equivalent with `-i -t`. – ridvanaltun Oct 08 '21 at 13:04
  • 3
    As you mentioned, `-t` or `--tty` allocates a pseudo-TTY. It simply means that a terminal is allocated which you can use to interact with container. If you want to know why they used the term _pseudo-TTY_, then you should read about the history of Unix, `tty`, physical terminals which were used to access computers back then etc. If you try something like `docker run -t ubuntu bash`, you'll see that you'll get a terminal but you can't interact with the container. That's where the `-i` or `--interactive` comes to the stage. This flag _Keep STDIN open even if not attached_. – Stefan Golubović Oct 08 '21 at 14:30
  • 1
    So, if you now try `docker run -i -t ubuntu bash`, you'll be able to use the terminal and execute commands in a container. And with most CLI tools, you can combine those short option into one. You can say `docker run -it` instead of `docker run -i -t`. Just like you can use `ls -lah` instead of `ls -l -a -h`. – Stefan Golubović Oct 08 '21 at 14:34
  • 1
    Ok, starts to be more clear. So docker run has its stdout directed to the terminal from where it is executed (in contrast to docker start). Without -i there is simply no way to interact with the container. Adding -i let me interact but in a very basic form (for instance I have to type "exit", I cannot ctrl-c. And adding -t provides a full blown terminal. – sr-01-01 Oct 08 '21 at 15:33

2 Answers2

2

Those are called flags and a flag can either be combined or separated, either in short (-) or long format (--). So:

docker run --interactive --tty hello-world

docker run --interactive -t hello-world

docker run -i --tty hello-world

docker run -i -t hello-world

docker run -it hello-world

are all the same.

As to how -i and -t works, refer to this

Fariz Awi
  • 43
  • 6
0

In this above simple example it will work the same.

In the last example container will print "Hello..." and exit in contrary to when you start interactive mode: https://phoenixnap.com/kb/docker-run-command-with-examples (-i -t -it will work the same)

For the difference cmd and entrypoint refer here: What is the difference between CMD and ENTRYPOINT in a Dockerfile?

chomar.c
  • 61
  • 5