6.1.2.3 Container Runtime Arguments
A focused guide to Container Runtime Arguments, connecting core concepts with practical Docker and container operations.
Container runtime arguments are values supplied at docker run time, appended to or overriding an image's default CMD, allowing a container's specific startup behavior to be customized without needing a different image for each variation.
Overriding CMD With Runtime Arguments
Arguments supplied after the image name at docker run time replace the image's CMD entirely, unless the image uses ENTRYPOINT, in which case they are passed as arguments to the entrypoint instead.
CMD ["python", "app.py"]
docker run myapp
docker run myapp python app.py --debug
The second invocation entirely replaces the image's default CMD with the explicitly supplied command and arguments.
Passing Arguments to an ENTRYPOINT
When an image defines ENTRYPOINT, runtime arguments are appended to it rather than replacing it entirely, providing a way to customize behavior while keeping the entrypoint itself fixed.
ENTRYPOINT ["python", "manage.py"]
CMD ["runserver"]
docker run myapp migrate
This runs python manage.py migrate, with the runtime argument migrate replacing the default CMD portion while the fixed ENTRYPOINT portion remains unchanged.
Why This Flexibility Is Useful
The ability to override or extend a container's startup command at run time, without modifying the underlying image, supports using the same image for multiple related purposes — running the main application, running a one-off management command, running tests — each invoked with different runtime arguments.
docker run myapp:1.0 python manage.py shell
docker run myapp:1.0 python manage.py migrate
Why Container Runtime Arguments Matter
Understanding exactly how runtime arguments interact with an image's ENTRYPOINT and CMD is essential for using a single image flexibly across multiple invocation patterns, rather than needing a separate, nearly identical image purpose-built for every variation in startup behavior.