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:
- What happens internally during a build
- The most important Dockerfile instructions
- The difference between build-time and runtime concepts
- How layers and caching work
1. What Happens When You Run docker build
When you execute:
docker build -t myapp .
Docker performs these steps:
- Reads the Dockerfile.
- Sends the build context (the current directory) to the Docker daemon.
- Executes each instruction one by one.
- Creates a new image layer for most instructions.
- Caches each layer for future builds.
- Produces a final image.