I am new to docker, has a simple question to the dockfile. We can write entrypoint and CMD in dock file. Seems that entrypoint is executed during creating container. And CMD is executed during starting container. Is this true?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
Not exactly:
ENTRYPOINT
configures a container that will run as an executable.So it is always executed (or the default
/bin/sh -c
is).You can view
CMD
as parameters for theENTRYPOINT
.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 (ifdocker run
is used without additional parameters).With
docker start
, as mentioned in issue 1437, theENTRYPOINT
is executed, but only with parameters fromCMD
(soCMD
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
, notdocker 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":
That means, if your Dockerfile includes: