Docker – difference between CMD and ENTRYPOINT

The CMD line in a Dockerfile defines the default command to run when a container is launched. If the command requires arguments then you need to use an array, for example [“cmd”, “-a”, “arga value”, “-b”, “argb-value”], which will be combined together and the command cmd -a arga value -b argb-valuewould be run.

An alternative approach to CMD is ENTRYPOINT. While a CMD can be overridden when the container starts, a ENTRYPOINT defines a command which can have arguments passed to it when the container launches. The default ENTRYPOINT is “/bin/sh -c” so even if we don’t define in the Dockerfile.

Lets do this with an example


Dockerfile – Using the busybox as base image I have copied the scripts. Here the entrypoint is “shell” which is executed always. Next line is command “” so if we do not override it then “” will be executed.


Lets see what we have in the scripts – “” prints FROM CONTAINER and “” prints the list of files.


Time to build the image and run the container


Running the container AS IS


Running the container with “”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s