Docker: Understanding ENTRYPOINT and CMD Instructions

I would like to ask a question about the ENTRYPOINT and CMD instructions available for use in a Docker file.

  • Ensuring that I mount local directories as volumes in the container using fig or docker-compose . When are the ENTRYPOINT and CMD instructions ENTRYPOINT ?
    • After the volumes have been mounted or earlier?
  • If you pass the bash script to ENTRYPOINT , will this script be executed every time the container starts?
  • If a bash script is added as an ENTRYPOINT , will all commands executed with docker run or docker exec be passed as arguments to this script?
  • When are CMD instauctions performed? As soon as the container was started and the volumes were installed?
  • Why can there be only one CMD in a Docker file? What if I want to run a container with multiple processes / run severa exacutables?
+5
source share
1 answer

1) ENTRYPOINT and CMD are executed in the order in which they are displayed in the Docker file, regardless of whether the volumes are mounted

2) if you have an ENTRYPOINT starting verb, you can pass a parameter

3) yes to start docker, but some examples can clarify this, and docker exec will just take you to the container

4) CMD is executed when the container starts

5) you can use several CMDs in the Docker file, but only the latter will be used, docker is designed to start a single process,

if you want to run several, you will need tools like the supervisor http://docs.docker.com/articles/using_supervisord or runit or s6 or daemontools see http://docs.docker.com/faq

Since CMD is easily reevaluated rather than ENTRYPOINT (unless you are docker run --entrypoint ), you usually use ENTRYPOINT as the last one line in your Dockerfile and CMD as the last line, being actually a parameter that can change

+1
source

All Articles