Dockerfile instructions at a glance
A Dockerfile is an ordered list of instructions that the Docker builder turns into an image. This reference lists every instruction with its exact syntax, whether it creates a new filesystem layer, and a best-practice note. Search the table to jump straight to the instruction you need.
How it works
Docker images are built as a stack of read-only layers. The builder reads your Dockerfile top to bottom and, for layer-creating instructions, runs the step inside a temporary container and commits the resulting filesystem diff as a new layer. Three instructions create layers — RUN, COPY and ADD — so the order and grouping of those lines directly controls image size and cache reuse.
Other instructions only change image configuration (metadata) rather than the filesystem: ENV, ARG, CMD, ENTRYPOINT, EXPOSE, LABEL, WORKDIR, USER, VOLUME, HEALTHCHECK, STOPSIGNAL, SHELL and ONBUILD. FROM is special — it begins a build stage by selecting a base image without adding a layer of its own.
Each instruction is also a cache key. If nothing above a line changed, Docker reuses the cached layer. That is why you copy and install dependencies before copying application source: dependency layers stay cached across code edits.
Tips and examples
- Combine related shell steps in a single
RUNwith&&and clean package caches in the same line so the cleanup lands in the same layer:
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
- Pair
ENTRYPOINTwithCMDfor a sensible default that callers can override:
ENTRYPOINT ["python", "app.py"]
CMD ["--port", "8080"]
- Use multi-stage builds and
COPY --from=builderto ship only compiled artifacts, keeping the runtime image small. - Run as a non-root
USER, add aHEALTHCHECK, and label images with theorg.opencontainers.image.*convention for traceability.