CMD
The Dockerfile instruction that sets the default command a container runs when you do not give one.
In more detail
Anything you type after the image name in docker run replaces CMD. When an ENTRYPOINT is set, CMD becomes its default arguments instead. Write it in exec form, a JSON array of the program and its arguments, so the program receives stop signals directly. Only the last CMD in a Dockerfile counts.
Examples
CMD ["python", "app.py"]CMD ["node", "dist/index.js"] after USER nodeRelated terms
- ENTRYPOINT — The Dockerfile instruction that sets the program a container always runs, with CMD supplying its default arguments.
- exec form — Writing RUN, CMD or ENTRYPOINT as a JSON list such as ["python", "app.py"], so the program runs directly without a shell.
- init process — The first process started on a system or in a container, with process ID 1 and special duties.
- graceful shutdown — Stopping a service in an orderly way: finish current work, close connections, then exit.
- Dockerfile — A text file of instructions, such as FROM, COPY and RUN, that tells Docker how to build an image.
- USER — The Dockerfile instruction that sets which user later instructions and the container run as.
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
- Minimal Base Images: Less To Attack — Certified Kubernetes Security Specialist (CKS) Exam Prep
- An Image That Runs As Root: Security Best Practices — CompTIA Cloud+ (CV0-004) Exam Prep
- Union Filesystems, Images And Writable Layers — Docker Architecture & Production Containers
- Docker, OCI, The Engine And The CLI — Docker Architecture & Production Containers
- Pull And Inspect A Third Party Image — Docker Architecture & Production Containers
- Run The Spine Service And Publish Its Port — Docker Architecture & Production Containers
- Build Context, Dockerignore And Your First Dockerfile — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Containerization Architecture: Multi-Stage Dockerfiles — Production Full-Stack Engineering
- Two Managers Down: The Night The Swarm Froze — Docker Certified Associate (DCA) Exam Prep
- Five Nodes Before Lunch: Building A Swarm — Docker Certified Associate (DCA) Exam Prep
- From docker run To docker service: Replicas, Global Mode And Updates — Docker Certified Associate (DCA) Exam Prep
- One File, Five Services: Stacks From Compose Files — Docker Certified Associate (DCA) Exam Prep
- The Same Shop On Kubernetes: Pods, Services And Storage For The DCA — Docker Certified Associate (DCA) Exam Prep
- Orchestration Sprint: Eight Calls In Eight Minutes — Docker Certified Associate (DCA) Exam Prep
- Twelve Lines, Ten Warnings: Dockerfile Instructions And hadolint — Docker Certified Associate (DCA) Exam Prep
- One Edited File, Six Rebuilt Steps: Layers, Cache And Flat Images — Docker Certified Associate (DCA) Exam Prep
- Works On My Laptop: Images, Containers, Volumes And Networks — CompTIA Linux+ (XK0-006) Exam Prep
- One Rule, Four Firewalls: firewalld, ufw, nftables And iptables — CompTIA Linux+ (XK0-006) Exam Prep
- Three PBQs Against The Clock: A Performance-Based Mock On Both Families — CompTIA Linux+ (XK0-006) Exam Prep