What Does the -I Flag Do in Docker?

What Does the -I Flag Do in Docker?

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.

1

3 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.

3

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.

4

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.