I'd like to ask some question about ENTRYPOINT
and CMD
instructions available for use in a Dockerfile.
- Providing that I'm mounting local directories as volumes in a container using
fig
or docker-compose
. When exactly are ENTRYPOINT
and CMD
instructions executed?
- After the volumes were mounter or before?
- If I pass a bash script to
ENTRYPOINT
, will this script be executed each time a container is started?
- If there is a bash script added as
ENTRYPOINT
, will all commands executed with docker run
or docker exec
be passed as arguments to this script ?
- When exactly are
CMD
instauctions executed? Once a container was started and volumes mounted ?
- Why can there only be one
CMD
in a Dockerfile? What if I want to start a container with several processes / run severa exacutables?
1) ENTRYPOINT and CMD are executed in the order they appear in the Dockerfile, regardless of the volumes mount
2) if you have an ENTRYPOINT launching a verb, you can pass a parameter
3) yes for docker run but some examples might clarify this, and docker exec just gets you inside the container
4) CMD executes when a container is launched
5) you can use several CMD in a Dockerfile, but only the last one will be used, docker is designed to run one process,
if you want to run several, you will need some tools such as supervisor http://docs.docker.com/articles/using_supervisord or runit or s6 or daemontools see http://docs.docker.com/faq
As CMD is easily overriden and not ENTRYPOINT (unless you docker run --entrypoint
) usually you have ENTRYPOINT as the last by one line in your Dockerfile and CMD as the last line, being in fact the parameter, that can change