I was just reading THIS article on Docker , Its an article describing how to dockerize a simple application. The following command is executed:
$ docker run -t -i ubuntu:14.04 /bin/bash, and then, The following explanation is given:
Here we’ve again specified the docker run command and launched an ubuntu:14.04 image. But we’ve also passed in two flags: -t and -i. The -t flag assigns a pseudo-tty or terminal inside our new container and the -i flag allows us to make an interactive connection by grabbing the standard in (STDIN) of the container.
I don't understand the meaning of:
-i flag allows us to make an interactive connection by grabbing the standard in (STDIN)Thank you.
13 Answers
Docker's -i/--interactive allows you to send commands to the container via standard input ("STDIN"), which means you can "interactively" type commands to the pseudo-tty/terminal created by the -t switch.
I explained here that -i, --interactive keeps STDIN open even if not attached, which you need if you want to type any command at all.
That helps for pipes:
$ echo hello | docker run -i busybox cat helloMeaning: -i does not always need -t (tty), with tty being the text-terminal.
From the docs:
For interactive processes (like a shell), you must use
-i -ttogether in order to allocate a tty for the container process.-i -tis often written-itas you’ll see in later examples. Specifying-tis forbidden when the client is receiving its standard input from a pipe, as in:
$ echo test | docker run -i busybox catThe -t flag is how Unix/Linux handles terminal access. Historically, a terminal was a hardline connection, with real pieces of hardware.
Today however, a pseudo-terminal driver is used.
- Run a container with no flags and by default you have a stdout (standard output) stream.
- Run with the
-iflag, and you get a stdin (standard input) stream added, which accepts text as input. - Run with -t, usually with the -i and you have a terminal driver added, which if you want to interact with the process is likely what you want. It basically makes the container start to look and feel like a terminal session.
Running -t without -i, means that you will have the terminal, but your input will not be connected to the terminal input.