4.1.1.5 Dockerfile Startup Definition
A focused guide to Dockerfile Startup Definition, connecting core concepts with practical Docker and container operations.
Dockerfile startup definition refers specifically to the combination of ENTRYPOINT and CMD instructions that together determine exactly what process executes, and with what arguments, the moment a container starts from the resulting image.
CMD Alone: A Simple, Overridable Default
When only CMD is specified, it defines the entire default command, which can be completely replaced by specifying a different command when starting a container.
CMD ["python", "app.py"]
docker run myapp
docker run myapp python -c "print('overridden entirely')"
ENTRYPOINT Alone: A Fixed Executable
When only ENTRYPOINT is specified, it defines a fixed executable that always runs, with anything supplied at docker run time appended as arguments rather than replacing it.
ENTRYPOINT ["python", "app.py"]
docker run myapp --debug
This runs python app.py --debug, appending the supplied argument rather than replacing the entrypoint command.
Combining Both for Configurable Defaults
The most common pattern combines both: ENTRYPOINT defines the fixed program to run, while CMD supplies default arguments that can still be overridden independently of the entrypoint itself.
ENTRYPOINT ["python", "app.py"]
CMD ["--mode", "production"]
docker run myapp
docker run myapp --mode development
The first command runs with the default arguments from CMD; the second overrides just the arguments while still executing through the same fixed ENTRYPOINT.
Exec Form for Correct Signal Handling
Writing the startup definition using the JSON array (exec) form, rather than as a plain shell string, ensures the specified process becomes the container's actual main process, correctly receiving termination signals rather than a wrapping shell intercepting them.
CMD ["python", "app.py"]
Why the Startup Definition Matters
The startup definition is the single most consequential piece of runtime configuration in a Dockerfile, since it determines exactly what a container does the moment it starts — getting it right, including correct signal handling, is essential for containers to behave predictably under restart, scaling, and shutdown.