Skip to main content
Dockerfile Instructions What each instruction means, with copy-exact examples. Following the official Dockerfile reference (as of 2026-06).

Instruction overview

RUN shell form vs exec form

Merging multiple RUN into one (with && and \) reduces layers and cleans the apt cache in the same layer.

The three commonly confused pairs

  • CMD is the “default command”; docker run myimg other-command completely overrides CMD.
  • ENTRYPOINT is the “fixed entry point”; args appended to docker run are appended after ENTRYPOINT, not overriding it.
  • Common combo: ENTRYPOINT holds the fixed executable, CMD holds overridable default args.
  • Write both in exec form (JSON array) so PID 1 is the app itself and can receive SIGTERM for a graceful shutdown; shell form wraps a /bin/sh -c and the signal never reaches the app.
Full interaction:

Other common instruction examples

EXPOSE is only a declaration, it does not open a port; a non-existent user for USER must be created first with RUN useradd.

Next

Reference: docs.docker.com/reference/dockerfile