Commands in dockerfile: run, cmd, entrypoint, copy and add

To sum up,
there can be more than one run, and there can be only one cmd and entrypoint (usually used to run apps)

cmd can be overwritten by docker command, entrypoint cannot

 

This command will be run when the container is started and docker run does not specify other commands.

  1. If docker run specifies other commands, the default command specified by CMD will be ignored.

  2. If there are multiple CMD instructions in the Dockerfile, only the last CMD is valid.

 

The Exec format of ENTRYPOINT is used to set the command to be executed and its parameters, and additional parameters can be provided through CMD.

The parameters in ENTRYPOINT will always be used, and the additional parameters of CMD can be dynamically replaced when the container starts.

For example, the following Dockerfile fragment:

ENTRYPOINT ["/bin/echo", "Hello"]  

CMD ["world"]

 

When the container is started via docker run -it [image], the output is:

Hello world

 

And if it is started by docker run -it [image] CloudMan, the output is:

Hello CloudMan

Published 72 original articles · praised 4 · 40,000+ views

Guess you like

Origin blog.csdn.net/qq_15156403/article/details/105472052