0
0
Dockerdevops~10 mins

FROM instruction for base image in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - FROM instruction for base image
Start Dockerfile
Read FROM instruction
Pull base image if not local
Set base image as build stage
Continue with next instructions
Build image on top of base
Docker reads the FROM instruction first, pulls the base image if needed, and sets it as the starting point for the build.
Execution Sample
Docker
FROM ubuntu:22.04
RUN apt-get update
RUN apt-get install -y curl
This Dockerfile starts from the Ubuntu 22.04 base image, updates package lists, and installs curl.
Process Table
StepInstructionActionResult
1FROM ubuntu:22.04Check local images; pull if missingBase image ubuntu:22.04 set
2RUN apt-get updateRun update command inside base imagePackage lists updated
3RUN apt-get install -y curlInstall curl packagecurl installed
4End of DockerfileBuild completeFinal image created
💡 All instructions executed; image built on ubuntu:22.04 base
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
Base ImageNoneubuntu:22.04ubuntu:22.04ubuntu:22.04ubuntu:22.04 with curl
Packages InstalledNoneNoneNonecurlcurl
Package ListsOutdatedUpdatedUpdatedUpdatedUpdated
Key Moments - 2 Insights
Why does Docker pull the base image during the FROM instruction?
Docker pulls the base image if it is not already on the local machine to ensure the build starts from the correct environment, as shown in execution_table step 1.
Can you have multiple FROM instructions in one Dockerfile?
Yes, multiple FROM instructions create multiple build stages, but each FROM sets a new base image, starting a new stage. This example shows a single FROM for simplicity.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the base image set after step 1?
ANone
Bcurl
Cubuntu:22.04
Dapt-get
💡 Hint
Check the 'Result' column in step 1 of the execution_table.
At which step are package lists updated?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Result' columns in the execution_table for step 2.
If the base image was already local, what would change in step 1?
ADocker would skip pulling and use local image
BDocker would pull the image anyway
CDocker would fail the build
DDocker would remove the local image
💡 Hint
Refer to the 'Action' description in step 1 about checking local images.
Concept Snapshot
FROM instruction sets the base image for your Docker build.
Docker pulls this image if not present locally.
All following instructions build on top of this base.
You can have multiple FROMs for multi-stage builds.
Always specify a valid image name and tag.
Full Transcript
The FROM instruction in a Dockerfile tells Docker which base image to use for building your container image. When Docker reads FROM, it checks if the image is available locally. If not, it downloads (pulls) the image from a registry. This base image becomes the starting point for all following build steps. For example, FROM ubuntu:22.04 sets the base to Ubuntu 22.04. Then commands like RUN apt-get update run inside that base. The build ends when all instructions are done, producing a new image layered on top of the base. Multiple FROM instructions can create multi-stage builds, each starting fresh with a new base image.