Skip to main content

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

ObjectWhat it isAnalogy
Dockerfilea text file with commands (FROM, RUN, COPY, CMD, etc.)recipe
Docker imagethe result of building from the Dockerfile, a ready filesystem and environmentfinished dish

The connection

  1. You write a Dockerfile
  2. You run:
bash
docker build -t myimage .
  1. Docker reads the Dockerfile and creates an image
  2. A container can be run from the image:
bash
docker run myimage

The 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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.