It is also a script, one uses CMD[“/opt/setup.sh”], the other uses entrypointe [“/opt, setup.sh”]. at this time, I start the container with docker run -d, at this time, it can be up with CMD, but entrypointe is existing, and it cannot be started yet. I checked the difference between CMD and entrypointe and other data, and found no reason. I want to know what is his principle for this purpose.
The difference is that the ENTERPOINT is not overwritten and CMD is overwritten.
For example, the same applies.
docker run -it --rm <image_name> hello world
If it is
ENTERYPOINT ["/bin/bash"]Then the actual command is
/bin/bash hello world
If it is
CMD ["/bin/bash"]Then the actual command is
That is, when running the container, the command is passed as the parameter of ENTERYPOINT. CMD is directly replaced when CMD is used.
Therefore, there is a tricky usage to use both in dockerfile:
ENTRYPOINT ["mongod"] CMD ["--help"]
In this way, users can not only customize the parameters for starting mongod, but also use –help to display help information by default when no parameters are specified.