简体   繁体   English

Docker:了解ENTRYPOINT和CMD指令

[英]Docker: understanding ENTRYPOINT and CMD instructions

I'd like to ask some question about ENTRYPOINT and CMD instructions available for use in a Dockerfile. 我想问一些关于可以在Dockerfile中使用的ENTRYPOINTCMD指令的问题。

  1. Providing that I'm mounting local directories as volumes in a container using fig or docker-compose . 假设我使用figdocker-compose将本地目录作为卷安装在容器中。 When exactly are ENTRYPOINT and CMD instructions executed? 何时执行ENTRYPOINTCMD指令?
    • 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? 如果我将bash脚本传递给ENTRYPOINT ,每次启动容器时都会执行此脚本吗?
  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 ? 如果有一个bash脚本添加为ENTRYPOINT ,那么使用ENTRYPOINT docker rundocker exec执行的所有命令都将作为参数传递给此脚本吗?
  4. When exactly are CMD instauctions executed? 何时执行CMD恢复? Once a container was started and volumes mounted ? 容器启动并安装卷后?
  5. Why can there only be one CMD in a Dockerfile? 为什么Dockerfile中只能有一个CMD What if I want to start a container with several processes / run severa exacutables? 如果我想启动一个包含多个进程的容器/运行severa exacutables怎么办?

1) ENTRYPOINT and CMD are executed in the order they appear in the Dockerfile, regardless of the volumes mount 1)ENTRYPOINT和CMD按它们在Dockerfile中出现的顺序执行,无论卷安装如何

2) if you have an ENTRYPOINT launching a verb, you can pass a parameter 2)如果你有ENTRYPOINT启动动词,你可以传递一个参数

3) yes for docker run but some examples might clarify this, and docker exec just gets you inside the container 3)是的,对于docker run,但是一些例子可能会澄清这一点,而docker exec只是让你进入容器

4) CMD executes when a container is launched 4)CMD在容器启动时执行

5) you can use several CMD in a Dockerfile, but only the last one will be used, docker is designed to run one process, 5)你可以在Dockerfile中使用几个CMD,但只使用最后一个,docker设计用于运行一个进程,

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 如果你想运行几个,你需要一些工具,如主管http://docs.docker.com/articles/using_supervisord或runit或s6或daemontools,请参阅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 由于CMD很容易被覆盖,而不是ENTRYPOINT(除非你的docker run --entrypoint ),你的Dockerfile中最后一行是最后一行,而最后一行是CMD,实际上是参数,可以改变

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM