Not exactly:
ENTRYPOINT
configures a container that will run as an executable.
So it is always executed (or the default /bin/sh -c
is).
ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
ENTRYPOINT command param1 param2 (shell form)
Command line arguments to docker run <image>
will be appended after all elements in an exec form ENTRYPOINT
, and will override all elements specified using CMD.
The shell form prevents any CMD
or run command line arguments from being used, but has the disadvantage that your ENTRYPOINT
will be started as a subcommand of /bin/sh -c
, which does not pass signals.
This means that the executable will not be the container’s PID 1 - and will not receive Unix signals - so your executable will not receive a SIGTERM from docker stop <container>
.
You can view CMD
as parameters for the ENTRYPOINT
.
if there is no entrypoint (the default command is "/bin/sh -c
"), CMD
can include an executable.
If ENTRYPOINT
already runs an executable, then the CMD arguments are parameters to this command (if docker run
is used without additional parameters).
With docker start
, as mentioned in issue 1437, the ENTRYPOINT
is executed, but only with parameters from CMD
(so CMD
is used, but you cannot override it with parameters of your own on the command-line).
IF you want to use CMD, you need docker run
, not docker start
.
There actually is a recent PR in progress (PR 19746) which allows for the docker start command to take an optional --cmd
(-c
) flag to specify the cmd to use instead of the default one from cmd/entrypoint.
The Official Dockerfile documentation now has a section "Understand how CMD and ENTRYPOINT interact":
- Dockerfile should specify at least one of
CMD
or ENTRYPOINT
commands.
ENTRYPOINT
should be defined when using the container as an executable.
CMD
should be used as a way of defining default arguments for an ENTRYPOINT
command or for executing an ad-hoc command in a container.
CMD
will be overridden when running the container with alternative arguments.
That means, if your Dockerfile includes:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…