✦ For everyone, free.

Practical knowledge for real and everyday life

Home

6.2.2.2 Interactive Stdin Attachment

A focused guide to Interactive Stdin Attachment, connecting core concepts with practical Docker and container operations.

Interactive stdin attachment, controlled by the -i flag, keeps a container's standard input stream open and connected to the launching terminal, allowing input to actually be sent to the container's process rather than that process immediately seeing an already-closed input stream.

Why Standard Input Needs to Stay Open

Without -i, a container's standard input is closed immediately, meaning any process expecting to read input interactively receives nothing at all, often causing it to behave unexpectedly or exit immediately.

docker run ubuntu:22.04 bash

Without -i (and -t), this typically exits almost immediately, since the shell has no open input to read from and nothing meaningful to do.

Enabling Input With -i

Adding -i keeps standard input open, allowing typed input to actually reach the container's process.

docker run -i ubuntu:22.04 cat

Typing text after running this command echoes it back, since cat is reading from the now-open standard input stream.

Combining With -t for a Full Interactive Experience

While -i alone allows input, combining it with -t (allocating a pseudo-terminal) provides the complete interactive experience most users actually expect, including proper line editing and prompt rendering.

docker run -it ubuntu:22.04 bash
Using -i Without -t for Piped Input

Some scenarios specifically want standard input open without full terminal allocation, such as piping data into a container's process programmatically.

cat input.txt | docker run -i myapp:1.0 process-stdin.sh
Why Interactive Stdin Attachment Matters

Understanding -i's specific role — keeping standard input genuinely open and usable — clarifies why omitting it causes interactive programs to behave as though no input is available at all, even when a terminal has otherwise been correctly allocated.