exec form
Writing RUN, CMD or ENTRYPOINT as a JSON list such as ["python", "app.py"], so the program runs directly without a shell.
In more detail
In shell form, CMD python app.py actually runs /bin/sh -c "python app.py": the shell becomes PID 1 and may not pass SIGTERM on, so docker stop waits and then kills. Exec form runs your program as PID 1 directly. Exec form needs double quotes because it is JSON; shell form is still handy for RUN steps that use pipes or variables.
Examples
CMD ["python", "app.py"] # exec formCMD python app.py # shell formRelated terms
- CMD — The Dockerfile instruction that sets the default command a container runs when you do not give one.
- ENTRYPOINT — The Dockerfile instruction that sets the program a container always runs, with CMD supplying its default arguments.
- init process — The first process started on a system or in a container, with process ID 1 and special duties.
- SIGTERM — The signal that politely asks a process to finish its work and exit.
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
Taught in
- Container Images The Exam Way — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Design And Build: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Container Hardening: Distroless & Rootless — Cloud Security & DevSecOps Engineering
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers