Digital Marketing

Difference between CMD and ENTRYPOINT in Docker

Every commands, either passed as an argument or specified from CND instruction are passed as argument of binary specified in ENTRYPOINT.

/bin/sh -c is the default entrypoint. So if you specify CMD date without specifying entrypoint, Docker executes it as /bin/sh -c date.

By using entrypoint, you can change the behaviour of your container at run time that makes container operation a bit more flexible.
["/bin/date"]
With the entrypoint above, the container prints out current date with different format.
docker run -i clock_container +"%s"
docker run -i clock_container +"%F"

You can only have one of each of CMD and ENTRYPOINT in your Dockerfile. CMD has a few different forms: it can specify an executable, or just specify parameters for the executable in ENTRYPOINT. ENTRYPOINT always specifies the executable as its first argument.
CMD [“apachectl”, “-D”, “FOREGROUND”]
or
CMD [“-D”, “FOREGROUND”]
ENTRYPOINT [“apachectl”]
As you can see, each token in the full command is specified as a different argument to CMD and ENTRYPOINT and wrapped in double quotes. All arguments are enclosed within brackets.

Comments

Popular posts from this blog

MySQL Sandbox with the Sakila sample database

How to install elgg on Openshift