0
0
Dockerdevops~10 mins

Running a container with docker run - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Running a container with docker run
Start: User types docker run command
Docker CLI parses command
Check if image exists locally
Create container
Start container process
Container runs and outputs logs
Container stops or runs
This flow shows how the docker run command is processed: parsing, image check, container creation, and running.
Execution Sample
Docker
docker run hello-world
Runs the hello-world container which prints a welcome message and then exits.
Process Table
StepActionEvaluationResult
1User runs 'docker run hello-world'Command receivedStart processing
2Check if 'hello-world' image exists locallyImage found?No
3Pull 'hello-world' image from Docker HubDownload image layersImage downloaded
4Create container from 'hello-world' imageContainer createdContainer ready
5Start container processRun container's default commandContainer runs
6Container outputs welcome messagePrints to terminalMessage displayed
7Container process endsContainer stopsContainer exited
8docker run command endsContainer stoppedReturn to prompt
💡 Container finishes running the hello-world program and exits, ending the docker run command.
Status Tracker
VariableStartAfter Step 3After Step 5After Step 7
Image 'hello-world'Not presentDownloadedDownloadedDownloaded
Container stateNoneNoneRunningExited
OutputNoneNoneWelcome messageWelcome message
Key Moments - 2 Insights
Why does docker pull the image even if I just typed docker run?
Because docker run first checks if the image is available locally (see step 2). If not found, it pulls the image (step 3) before creating the container.
Does the container keep running after the hello-world message?
No, the container runs the hello-world program which prints a message and then exits (steps 6 and 7). The container stops immediately after.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Docker download the image?
AStep 3
BStep 2
CStep 5
DStep 6
💡 Hint
Check the 'Action' and 'Result' columns in step 3 for image download details.
According to the variable tracker, what is the container state after step 5?
AExited
BRunning
CNone
DPaused
💡 Hint
Look at the 'Container state' row under 'After Step 5' in the variable tracker.
If the image was already present locally, which step would be skipped?
AStep 6
BStep 4
CStep 3
DStep 7
💡 Hint
Step 3 is about pulling the image; if image exists, Docker skips pulling.
Concept Snapshot
docker run <image> : Runs a container from the specified image.
If image not local, Docker pulls it first.
Creates and starts the container.
Container runs its default command.
Output shows in terminal.
Container stops when command ends.
Full Transcript
When you run 'docker run hello-world', Docker first checks if the image is on your computer. If not, it downloads the image from the internet. Then it creates a container from that image and starts it. The container runs the program inside, which prints a welcome message. After the message, the container stops and the command finishes. This process happens step-by-step as shown in the execution table and variable tracker.