✦ For everyone, free.

Practical knowledge for real and everyday life

Home

4.2 Dockerfile Instructions

A focused guide to Dockerfile Instructions, connecting core concepts with practical Docker and container operations.

Dockerfile instructions are the specific keywords — FROM, RUN, COPY, ADD, ENV, WORKDIR, EXPOSE, USER, CMD, ENTRYPOINT, and others — that together make up the vocabulary used to describe how an image should be built and how containers started from it should behave by default.

Filesystem-Affecting Instructions

RUN, COPY, and ADD each produce a new layer reflecting a filesystem change, whether from executing a command or from copying files into the image.

RUN apt-get update && apt-get install -y curl
COPY app.py /app/app.py
ADD https://example.com/data.tar.gz /data/
Metadata-Setting Instructions

ENV, WORKDIR, EXPOSE, USER, and LABEL set configuration and metadata that apply to the resulting image and any containers started from it, without themselves producing new filesystem layers.

ENV NODE_ENV=production
WORKDIR /app
EXPOSE 8080
USER node
LABEL maintainer="team@example.com"
Startup-Defining Instructions

CMD and ENTRYPOINT define what process runs by default when a container starts, with their interaction determining whether and how that default can be overridden at run time.

ENTRYPOINT ["node"]
CMD ["server.js"]
Build-Stage Instructions

FROM (used multiple times) and ARG support multi-stage builds and build-time variables, letting a single Dockerfile define several distinct build stages or accept configurable values supplied at build time.

ARG VERSION=1.0
FROM node:20 AS build
FROM node:20-alpine
Why Knowing the Full Instruction Set Matters

A solid working knowledge of the available instructions, and which category each falls into (filesystem, metadata, startup, or build-stage), is the foundation for both reading an unfamiliar Dockerfile confidently and writing a new one that behaves exactly as intended, rather than relying on trial and error to discover what each instruction actually does.

docker build --help

Content in this section