✦ For everyone, free.

Practical knowledge for real and everyday life

Home

6.2.2 Interactive Mode

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

Interactive mode, invoked through -it, connects a container's standard input and a pseudo-terminal directly to the current terminal session, allowing direct, real-time interaction with whatever process is running inside the container.

Combining -i and -t

The -i flag keeps standard input open, and -t allocates a pseudo-terminal — together, they enable the kind of interactive experience expected when running a shell or other interactive program inside a container.

docker run -it ubuntu:22.04 bash

This drops directly into an interactive bash shell running inside a freshly created Ubuntu container, behaving much like an SSH session into a remote machine.

Why Both Flags Are Typically Needed Together

-i alone keeps standard input open but without a proper terminal, certain interactive behaviors (like a shell prompt rendering correctly) don't work as expected; -t alone allocates a terminal but without open standard input, nothing typed can actually be sent to the process.

docker run -i ubuntu:22.04 bash
docker run -it ubuntu:22.04 bash

The second command provides the complete interactive experience; the first, missing -t, behaves noticeably differently and less usefully for an interactive shell session.

Exiting an Interactive Session

Exiting the interactive process (typically by typing exit within a shell) ends the session and, by default, stops the container as well, since that process was the container's main process.

docker run -it ubuntu:22.04 bash
exit
docker ps -a

The container appears stopped, having ended when its main process (the interactive shell) exited.

Why Interactive Mode Matters

Interactive mode is essential for any workflow requiring direct, real-time interaction with a container's process — exploring an image's filesystem, debugging an application from within its own running environment, or simply experimenting with a tool inside an isolated container.

Content in this section