What Are The Differences between CMD and ENTRYPOINT in Docker?

Dockerfile has reserved words CMD and ENTRYPOINT.  They seem to do the same thing.  What are the differences between CMD and ENTRYPOINT in Docker besides their words' lengths?

There are many similarities between these two reserved words in Dockerfile "language."  But here are three differences:

#1  "...CMD can be overwritten by an argument to docker run, while ENTRYPOINT can be overwritten only by using the --entrypoint option of docker run." is a quote taken from page 43 of Docker Cookbook by Sebastien Goasguen.

If you want your Docker container to use different executables or parameters each time, CMD is preferable to ENTRYPOINT.

"If you would like your container to run the same executable every time, then you should consider using ENTRYPOINT in combination with CMD." taken from Docker's official website.

#2  CMD has three forms whereas ENTRYPOINT has only two forms.  The syntax associated with each of these forms will tell the Docker engine which to form to use.  The CMD forms are these: exec form (which is recommended), the default parameters method, and the shell form.  The ENTRYPOINT forms are these: exec form (recommended) and shell form.

You can read more about them here:

#3   In the history of Docker, CMD was a command before ENTRYPOINT become a supported reserved word.  This is relevant, external posting states this fact.  The Dockerfile used to be considered a manifesto (according to page 43 of Docker Cookbook by Sebastien Goasguen).  You can read more about the ways Docker has changed here.

Leave a comment

Your email address will not be published. Required fields are marked *