How does a Dockerfile differ from an image?
The difference is simple:
- A Dockerfile is a recipe (a set of instructions on how to build an image).
- A Docker image is the finished dish that results from executing those instructions.
Breakdown step by step
| Object | What it is | Analogy |
|---|---|---|
| Dockerfile | a text file with commands (FROM, RUN, COPY, CMD, etc.) | recipe |
| Docker image | the result of building from the Dockerfile, a ready filesystem and environment | finished dish |
The connection
- You write a Dockerfile
- You run:
bash
docker build -t myimage .- Docker reads the Dockerfile and creates an image
- A container can be run from the image:
bash
docker run myimageThe main difference in one phrase
A Dockerfile describes how to create an image, while an image is the final artifact that runs a container.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.