What exactly happens when you run docker run -i -t ubuntu /bin/bash?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
Docker pulls the ubuntu image if missing, creates a container with its own read-write filesystem layer and network interface/IP, then starts it running /bin/bash attached to your terminal (-i keeps STDIN open, -t allocates a TTY). Exiting stops but does not remove the container — restart or rm it explicitly.
Detailed explanation
The docs walk this canonical example through six steps: (1) pull — if ubuntu is not local, Docker fetches it as if you ran docker pull ubuntu; (2) create — equivalent to docker container create; (3) filesystem — Docker allocates a read-write layer on top of the image so the running container can create/modify files locally; (4) network — it creates an interface on the default network with an IP, bridged through the host for external access; (5) start + exec — it launches /bin/bash with your terminal attached because of -i (interactive STDIN) and -t (pseudo-TTY); (6) lifecycle — typing exit ends bash so the container stops, but it lingers (visible in docker ps -a) until you docker start it again or docker rm it. The same pattern scales to detached servers: docker run -d -p 8080:80 docker/welcome-to-docker returns the full container ID, publishes host 8080 → container 80, and keeps running until docker stop <short-id> — you only need enough ID characters to be unique (e.g. docker stop a1f).
Official docs:Docker docs: Docker overview
Example
docker run -i -t ubuntu /bin/bash
# 1. pull ubuntu (if missing) → 2. create container
# 3. read-write layer → 4. network + IP → 5. exec /bin/bash
# exit → container STOPS but is kept; then:
docker ps -a # see stopped container
docker start <id> # run it again
docker rm <id> # delete it (state not in volumes is lost)Interview tip
Recite the six steps in order and land on the stop-vs-remove distinction — interviewers use it to check you have actually operated containers, not just memorized flags.
Common mistakes
- Thinking exiting a container deletes it.
- Not knowing -i and -t are what attach the terminal, or that short IDs suffice.