简介
docker在非特权模式下,启动顺序由cmd和ENTRYPOINT 来控制,不是原有linux那一套启动流程,下面是
CMD 和 ENTRYPOINT 相互协作最终的命令执行结果,没时间翻译,直接官方粘过来的
规则
Both CMD
and ENTRYPOINT
instructions define what command gets executed when running a container. There are few rules that describe their co-operation.
-
Dockerfile should specify at least one of
CMD
orENTRYPOINT
commands. -
ENTRYPOINT
should be defined when using the container as an executable. -
CMD
should be used as a way of defining default arguments for anENTRYPOINT
command or for executing an ad-hoc command in a container. -
CMD
will be overridden when running the container with alternative arguments.
The table below shows what command is executed for different ENTRYPOINT
/ CMD
combinations:
结果
The table below shows what command is executed for different ENTRYPOINT / CMD combinations:
No ENTRYPOINT | ENTRYPOINT exec_entry p1_entry | ENTRYPOINT [“exec_entry”, “p1_entry”] | |
---|---|---|---|
No CMD | error, not allowed | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry |
CMD [“exec_cmd”, “p1_cmd”] | exec_cmd p1_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry exec_cmd p1_cmd |
CMD [“p1_cmd”, “p2_cmd”] | p1_cmd p2_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry p1_cmd p2_cmd |
CMD exec_cmd p1_cmd | /bin/sh -c exec_cmd p1_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd |
注意
Note: If CMD
is defined from the base image, setting ENTRYPOINT
will reset CMD
to an empty value. In this scenario, CMD
must be defined in the current image to have a value.
引用
https://docs.docker.com/engine/reference/builder/#entrypoint
k8s 规则
https://kubernetes.io/zh/docs/tasks/inject-data-application/define-command-argument-container/