what does the -i flag do in docker?

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.

  • Run a container with no flags and by default you have a stdout (standard output) stream.
  • Run with the -i flag, 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.


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.


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.

Tags:

Docker