Reputation: 2192
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.
Upvotes: 24
Views: 13507
Reputation: 11800
From the docs:
For interactive processes (like a shell), you must use
-i -t
together in order to allocate a tty for the container process.-i -t
is often written-it
as you’ll see in later examples. Specifying-t
is forbidden when the client is receiving its standard input from a pipe, as in:
$ echo test | docker run -i busybox cat
The -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.
-i
flag, and you get a stdin (standard input) stream added, which accepts text as input.Running -t
without -i
, means that you will have the terminal, but your input will not be connected to the terminal input.
Upvotes: 6
Reputation: 1326766
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
hello
Meaning: -i
does not always need -t (tty
), with tty
being the text-terminal.
Upvotes: 8
Reputation:
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.
Upvotes: 29