DELAPARRA
Index
Color
NL
Category: Docker

CMD

Explained by Updated

What is CMD?

CMD: The default command run when a container starts. Easily overridden by arguments to docker run. CMD sets the default command a container runs when it starts, such as CMD ["node", "server.js"]. If you pass a command to docker run, it replaces CMD. Use the JSON array form shown above. It runs the program directly as the main process, so it receives stop signals properly and can shut down cleanly. The shell form, CMD node server.js, wraps it in a shell that often does not forward signals, which makes containers slow to stop.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about CMD

What should you keep in mind with CMD?

CMD is often combined with ENTRYPOINT. The entrypoint is the fixed program, and CMD provides default arguments that are easy to override. A Dockerfile has only one effective CMD; if you write several, the last one wins. Keep it simple, because whoever runs the image should be able to tell at a glance what it starts.

What does an example of CMD look like?

CMD ["node", "server.js"]

At a glance

CategoryDocker
Explained by
Updated

More Docker terms

All terms starting with C

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.