Docker: When to Use ENTRYPOINT vs CMD
Understand ENTRYPOINT vs CMD in Docker with simple code examples
CMD
Provides default arguments or commands for the container.
Use Case:
It can be overridden by passing a command when you run the container.
If no command is provided at runtime, Docker will use the CMD instruction.
Use it when you want a default behavior but allow users to override it.
CMD ["nginx", "-g", "daemon off;"]Default: Runs
nginx -g "daemon off;".
Override:
docker run my-image bashRuns
bash, ignoringnginx.
ENTRYPOINT
Specifies the main, fixed command that will always run in the container.



