# Dockerfile

> A Dockerfile is a text file with the instructions to build a container image: base image, files, commands, user and the command to run.

- Source: https://www.itwonderlab.com/dockerfile/
- Published: 2026-10-06
- Updated: 2026-10-06
- Author: Javier Ruiz Jiménez (https://www.javierruizjimenez.com/)
- Site: IT Wonder Lab (https://www.itwonderlab.com/)

---

A **Dockerfile** lists the instructions that `docker build` follows to create an image. Each instruction (`FROM`, `COPY`, `RUN`, `USER`, `CMD`...) adds a layer, and Docker caches the layers that did not change.

### Key concepts

- **`FROM`** chooses the base image, and several `FROM` lines create a [multi-stage build](https://www.itwonderlab.com/docker-multi-stage-builds/).
- **Build cache**: put the instructions that change rarely first.
- **`.dockerignore`** keeps files and secrets out of the build context.
- **`CMD` and `ENTRYPOINT`** define what the container runs.
- **BuildKit** adds cache mounts, secret mounts and multi-platform builds. See [BuildKit and buildx](https://www.itwonderlab.com/docker-buildkit-buildx/).

### Learn it

[Dockerfile tutorial](https://www.itwonderlab.com/dockerfile-tutorial/).
