Skip to main content
This page explains how Docker handles standard input and terminal devices when you run a container, and how to make a container interactive so it can accept keyboard input and display prompts. Example: a simple prompt application
  • Running the script directly on the host behaves as expected:
  • If you dockerize that application and run the image without special flags, the container runs non-interactively: it isn’t attached to your keyboard or terminal device, so it prints only what goes to standard output and then exits.
Why this happens
  • By default docker run does not attach the container to your standard input (stdin) and does not allocate a pseudo-TTY. Even when you invoke docker run from a terminal, the container process is not connected to your keyboard or terminal device — it runs in non-interactive mode.
Keep stdin open: -i (interactive)
  • To keep the container’s standard input open so it can read data from you, add -i:
  • In this example the container read the input, but the prompt text (the “Welcome! Please enter your name:” line) may not be visible because many programs print prompts only when they detect they are attached to a terminal (a TTY).
Allocate a pseudo-TTY: -t
  • To make the program inside the container think it’s talking to a real terminal so it will print prompts, colorized output, progress bars, etc., allocate a pseudo-TTY with -t. Combine -i and -t for a full interactive session:
Quick reference table for flags Common use cases and patterns
  • Use -i alone when you want to pipe data into a container (stdin connected) but you don’t need a terminal. Example: streaming an SQL dump into a database container.
  • Use -t alone when you want the program to detect a terminal (for colored output or interactive formatting) but you don’t need to type into it.
  • For interactive command-line programs (REPLs, shells, text-based installers) you typically use -it together.
Use -i when piping/streaming data into a container. Use -t when you want the program to detect a terminal (colors, prompts). Use -it for an interactive terminal session.
Links and references

Watch Video