A Dockerfile is a text file that contains a sequence of instructions used to build a Docker image.

When you run docker build, Docker reads this file step by step and creates an image layer by layer.

This guide explains:


1. What Happens When You Run docker build

When you execute:

docker build -t myapp .

Docker performs these steps:

  1. Reads the Dockerfile.
  2. Sends the build context (the current directory) to the Docker daemon.
  3. Executes each instruction one by one.
  4. Creates a new image layer for most instructions.
  5. Caches each layer for future builds.
  6. Produces a final image.