dockerfile中CMD和ENTRYPOING真正的区别
世界只因有你
世界只因有你 2017-04-24 16:00:43
0
2
793

同样是一个脚本,一个用CMD["/opt/setup.sh"],一个用ENTRYPOING["/opt、setup.sh"],此时我都以docker run -d 去启动这个容器,此时用CMD的就可以up起来,但是ENTRYPOING却是Exited,而且他还不能start起来,我查了CMD和ENTRYPOING的区别等资料,都没有发现原因,我现在就想知道就我的这个而言,他的原理是什么?

世界只因有你
世界只因有你

reply all(2)
黄舟

The difference is that ENTERPOINT is not overwritten, but CMD will be.

For example, do the same docker run -it --rm <image_name> hello world

If yes ENTERYPOINT ["/bin/bash"] 那么实际运行的命令是 /bin/bash hello world

If yes CMD ["/bin/bash"] 那么实际运行的命令是 hello world.

That is, the command when running the container is passed as a parameter of ENTERYPOINT when ENTERYPOINT is used; when using CMD, CMD is directly replaced.

So there is a tricky way to use both in the 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

Ty80

Check the logs first

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!