Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: understanding ENTRYPOINT and CMD instructions

Tags:

docker

I'd like to ask some question about ENTRYPOINT and CMD instructions available for use in a Dockerfile.

  1. 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?
  2. If I pass a bash script to ENTRYPOINT, will this script be executed each time a container is started?
  3. 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 ?
  4. When exactly are CMD instauctions executed? Once a container was started and volumes mounted ?
  5. Why can there only be one CMD in a Dockerfile? What if I want to start a container with several processes / run severa exacutables?
like image 840
luqo33 Avatar asked Nov 09 '22 11:11

luqo33


1 Answers

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

like image 131
user2915097 Avatar answered Nov 15 '22 05:11

user2915097