Roadmap › Docker & Containers › Module: Core Concepts
Lessons in this course (8)

2. Dockerfile instructions

Basic★ Must knowLesson 2 of 8
InstructionPurpose
FROMBase image (can appear multiple times for multi-stage)
WORKDIRSet working directory
COPY / ADDCopy files (ADD also extracts tar and fetches URLs — prefer COPY)
RUNExecute a command at build time (creates a layer)
ENVEnvironment variable (build + runtime)
ARGBuild-time variable only
EXPOSEDocument the listening port (doesn't publish it)
USERRun as a non-root user
ENTRYPOINTThe executable that always runs
CMDDefault arguments (or command) — overridable at docker run
HEALTHCHECKCommand to test container health
LABEL, VOLUME, STOPSIGNAL, SHELLMetadata, mount points, signals

CMD vs ENTRYPOINT: ENTRYPOINT ["dotnet", "Api.dll"] fixes the program; CMD ["--urls", "http://+:8080"] supplies default args that docker run image <args> replaces. Use the exec form (JSON array) so the app is PID 1 and receives SIGTERM for graceful shutdown.