Dockerfile

A text file of instructions, such as FROM, COPY and RUN, that tells Docker how to build an image.

In more detail

Docker reads it top to bottom: FROM picks a base image, later instructions add files, run commands or set metadata, and each file-changing step becomes a layer. The order matters, because a change in one step invalidates the build cache for every step after it.

Examples

FROM python:3.12-alpine
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]
A three-stage Dockerfile: deps installs from the lockfile, builder compiles, runner copies only the output into a minimal image.
FROM golang:alpine AS build
RUN CGO_ENABLED=0 go build -o /out/app .
FROM eclipse-temurin:21-jdk AS build
RUN pip install --no-cache-dir --quiet kafka-python==2.2.15
The official Next.js with-docker example uses deps, builder and runner stages on node:alpine.

Related terms

Related guides

Taught in

References

Certification courses