Roadmap › Docker & Containers › Module: Core Concepts
Lessons in this course (8)
2. Dockerfile instructions
Basic★ Must knowLesson 2 of 8
| Instruction | Purpose |
|---|---|
FROM | Base image (can appear multiple times for multi-stage) |
WORKDIR | Set working directory |
COPY / ADD | Copy files (ADD also extracts tar and fetches URLs — prefer COPY) |
RUN | Execute a command at build time (creates a layer) |
ENV | Environment variable (build + runtime) |
ARG | Build-time variable only |
EXPOSE | Document the listening port (doesn't publish it) |
USER | Run as a non-root user |
ENTRYPOINT | The executable that always runs |
CMD | Default arguments (or command) — overridable at docker run |
HEALTHCHECK | Command to test container health |
LABEL, VOLUME, STOPSIGNAL, SHELL | Metadata, 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.