In Dockerfiles there are two commands that look similar to me: CMD
and ENTRYPOINT
. But I guess that there is a (subtle?) difference between them -
Difference between CMD and ENTRYPOINT by intuition:
Yes, it's mixing up.
You can override any of them when running docker run.
Difference between CMD and ENTRYPOINT by example:
docker run -it --rm yourcontainer /bin/bash <-- /bin/bash overrides CMD
<-- /bin/bash does not override ENTRYPOINT
docker run -it --rm --entrypoint ls yourcontainer <-- overrides ENTRYPOINT with ls
docker run -it --rm --entrypoint ls yourcontainer -la <-- overrides ENTRYPOINT with ls and overrides CMD with -la
More on difference between CMD
and ENTRYPOINT
:
Argument to docker run
such as /bin/bash overrides any CMD command we wrote in Dockerfile.
ENTRYPOINT cannot be overriden at run time with normal commands such as docker run [args]
. The args
at the end of docker run [args]
are provided as arguments to ENTRYPOINT. In this way we can create a container
which is like a normal binary such as ls
.
So CMD can act as default parameters to ENTRYPOINT and then we can override the CMD args from [args].
ENTRYPOINT can be overriden with --entrypoint
.