How is an image built from a Dockerfile?
An image is built from a Dockerfile with the docker build command, where Docker reads the file line by line and, at each step, forms a new layer of the future image.
The process, junior-style
- You write a Dockerfile - a set of instructions (
FROM,COPY,RUN,CMD, and so on). - You run the image build:
bash
docker build -t myimage .- Docker reads the Dockerfile top to bottom and:
- takes the base image (
FROM) - copies files (
COPY) - runs commands (
RUN) - sets up the environment
- Each instruction becomes a layer of the future image.
- After executing all the instructions, Docker saves the image under the given name and tag (
myimage).
What is important to understand
-
Docker caches layers - if a line has not changed, the layer is not rebuilt.
-
The build result is an image, which you can view with:
bashdocker images
Summary
Docker builds an image by executing the Dockerfile instructions step by step during
docker build, forming a layered template of a container ready to run.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.