Front-end World

Front-end World

Docker: When to Use ENTRYPOINT vs CMD

Understand ENTRYPOINT vs CMD in Docker with simple code examples

Kristiyan Velkov's avatar
Kristiyan Velkov
Feb 18, 2025
∙ Paid

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 bash
  • Runs bash, ignoring nginx.



ENTRYPOINT

Specifies the main, fixed command that will always run in the container.

User's avatar

Continue reading this post for free, courtesy of Kristiyan Velkov.

Or purchase a paid subscription.
© 2026 © 2025 Kristiyan Velkov. All rights reserved. · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture