Skip to main content
Consider a simple prompt application that asks for your name and prints a welcome message when run locally:
If you dockerize this application and run it in a container, the container will not wait for the prompt by default. It prints whatever the application writes to standard output because Docker does not keep the container’s standard input connected to your terminal unless you ask it to. Even though you’re attached to the container’s console, the process inside the container has no terminal allocated and therefore cannot read input interactively. Example outputs when running the container:
Because the container had no stdin connected, the program printed the greeting with an empty name. If you run with the -i flag to keep STDIN open, the container accepts input:
Note that in the -i run above the original prompt text (“Welcome! Please enter your name:”) is missing. Many programs only print interactive prompts when they detect they’re attached to a terminal (a TTY). To make programs inside the container behave as if they have a real terminal, allocate a pseudo-TTY with the -t flag.
  • -i keeps STDIN open so the container can receive input.
  • -t allocates a pseudo-TTY so programs behave like they are running in a real terminal (show prompts, colors, progress UIs).
  • -it (or -ti) combines both: keeps STDIN open and allocates a TTY.
For the same interactive behavior you see locally, run:
When to use each flag
  • Use -i alone when you need to stream or pipe data into the container (STDIN must be connected, but you don’t need a terminal). Example:
  • Use -t alone when you want the containerized process to think it’s running in a terminal (so it emits colored output, progress bars, etc.), but you don’t need to type into it yourself.
  • Use -it for interactive shells and most CLI interactions where both input and terminal behavior are required (e.g., bash shells, interactive installers).
Summary table Further reading
Use -i to keep STDIN open, use -t to allocate a pseudo-TTY, and combine them as -it when you need both interactive input and terminal-like behavior. For streaming or pipelines, prefer -i without -t.

Watch Video