> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Interactive Mode

> Explains Docker run interactive flags -i, -t and -it, how STDIN and pseudo TTY affect prompts and when to use each for interactive or streamed container input

Consider a simple prompt application that asks for your name and prints a welcome message when run locally:

```bash theme={null}
$ ./app.sh
Welcome! Please enter your name: Mumshad
Hello and Welcome Mumshad!
```

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:

```bash theme={null}
$ docker run kodekloud/simple-prompt-docker
Hello and Welcome !
```

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:

```bash theme={null}
$ docker run -i kodekloud/simple-prompt-docker
Mumshad
Hello and Welcome Mumshad!
```

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:

```bash theme={null}
$ docker run -it kodekloud/simple-prompt-docker
Welcome! Please enter your name: Mumshad
Hello and Welcome Mumshad!
```

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:

```bash theme={null}
$ cat data.txt | docker run -i myimage
```

* 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

| Flag | What it does | Common use case |
| - | - | - |
| `-i` | Keep STDIN open | Streaming or piping data into container (`cat file \| docker run -i ...`) |
| `-t` | Allocate a pseudo-TTY | Make programs emit colors / progress UI when no input typing is needed |
| `-it` | Both STDIN open + pseudo-TTY | Interactive shells and command-line applications that prompt for input |

Further reading

* [Docker run reference (official)](https://docs.docker.com/engine/reference/run/)
* [Docker CLI overview](https://docs.docker.com/engine/reference/commandline/cli/)

<Callout icon="lightbulb" color="#1CB2FE">
  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`.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/docker-training-course-for-the-absolute-beginner/module/7a88081c-a9d0-45cc-b75e-55c93b6886d6/lesson/76cb7719-4b2c-4268-855b-fb8e1bbdae6e" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.