Docker -i and -t: stdin and interactive terminals
Input is not a terminal
Standard input (stdin) is a stream of data a process can read. A pseudo-terminal (TTY) provides terminal behavior, such as interactive input handling. Docker’s -i keeps input available; -t supplies a pseudo-terminal. The combined -it is convenient for many interactive shells, but a script passing data through a pipe generally needs only -i.
Lab prerequisites
Use an approved disposable Linux-container lab only. Verify the active context (docker context show), CLI/daemon versions and that the instructor has reviewed and preloaded the BusyBox 1.37 fixture for the target platform; record its digest before use. The tag is inherited from earlier chapters, not a verified immutable identity. --pull=never avoids automatic downloads; --network none isolates normal network access for these local-only tasks. Verify each bm-v04 name is unused; if not, choose a fresh name consistently. Run host commands one at a time in Bash, stop on unexpected errors, and clean up only the container you created. If a fixture times out, inspect its state before retrying; remove only your stopped fixture. All snippets are static, not executed by ByteMind. Before any engine request, confirm the effective approved daemon endpoint, including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides; do this privately in each terminal. Confirm the local tag still resolves to the approved image identity and platform. If any check fails, use the paper exercise instead. The network flag limits container networking, not the client-to-daemon connection. Use a lab with readable, local-only logging and an owner-set execution time limit; confirm your fixture identity before every cleanup.
Send a line through a pipe
The host printf sends a line to the container’s cat program. cat reads until the input closes and prints apple followed by a newline. The disposable container is removed after it exits. No terminal allocation is necessary.
printf 'apple\n' | docker run --rm -i --pull=never --network none --name bm-v04-pipe busybox:1.37 catOpen a separate interactive shell
In a real terminal, create the waiting fixture and open an additional shell. Inside that shell run echo terminal and then exit. Back on the host, verify the original process is still running and clean it up before the 300-second wait expires.
docker run -d --pull=never --network none --name bm-v04-tty busybox:1.37 sleep 300docker exec -it bm-v04-tty shdocker container inspect --format '{{.State.Status}}' bm-v04-ttydocker stop bm-v04-ttydocker rm bm-v04-ttyCommon mistakes
Do not add -t to every pipeline: terminal allocation can fail with non-terminal input and can change output formatting or stream handling. An interactive shell is not inherently a privileged shell; the flags change I/O, not the access policy. For scripts that consume machine-readable output, omit the terminal unless it is genuinely required. A TTY can combine stdout and stderr into a single terminal stream. Keep noninteractive output unallocated when a program needs to distinguish those streams.
Manual practice
Change the pipe example to send two lines, red and blue. Predict the output and explain why no TTY is needed. Then identify the flags needed when a human must use the interactive shell in the second example.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker -i and -t: stdin and interactive terminals — Knowledge check
Apply the concepts from this lesson.
What does -i change?
Which flag is normally unnecessary when piping text into cat?
Does -it grant extra Linux capabilities?