CMD
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.
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
| Category | Docker |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |