[英]confused with CMD and ENTRYPOINT in dockerfile
I have known that in the dockerfile, when ENTRYPOINT and CMD are both provided, the values in CMD will be as default parameter of ENTRYPOINT, then when running a container with additional parameter, the additional parameter will replace the values of CMD in dockerfile. 我知道在dockerfile中,当提供ENTRYPOINT和CMD时,CMD中的值将作为ENTRYPOINT的默认参数,然后当运行带有附加参数的容器时,附加参数将替换dockerfile中的CMD值。
but when I see the dockerfile of mongodb, I'm confused, the entrypoint and cmd part of its dockerfile: 但是当我看到mongodb的dockerfile时,我很困惑,它的dockerfile的入口点和cmd部分:
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 27017
CMD ["mongod"]
I know when I run docker run mongo:latest
this will be docker-entrypoint.sh mongod
, but when I run docker run mongo:latest --auth
, why could it run correctly? 我知道当我运行docker-entrypoint.sh mongod
docker run mongo:latest
这将是docker-entrypoint.sh mongod
,但当我运行docker run mongo:latest --auth
,为什么它能正常运行? Won't it be docker-entrypoint.sh --auth
? 它不是docker-entrypoint.sh --auth
? since the --auth
will replace mongod
, so why I run docker run mongo --auth
but it works fine? 因为--auth
将取代mongod
,所以为什么我运行docker run mongo --auth
但它运行正常?
The mongod Dockerfile references docker-entrypoint.sh
. mongod Dockerfile引用docker-entrypoint.sh
。
That script docker-entrypoint.sh
starts by testing if the first parameter begins with ' -
' (as in ' --auth
'): 该脚本docker-entrypoint.sh
首先测试第一个参数是否以' -
'开头(如' --auth
'):
if [ "${1:0:1}" = '-' ]; then
set -- mongod "$@"
fi
So the arguments become mongod --auth
, not just --auth
. 因此争论变成了mongod --auth
,而不仅仅是 - --auth
。
Meaning: 含义:
mongod
, you don't have to type mongod
first when using docker run
: it will be added for you in docker-entrypoint.sh
如果你必须在 mongod
之后传递任何参数,你不必在使用docker run
时首先输入mongod
:它将在docker-entrypoint.sh
为你添加 mongod
, you don't have to type mongod
either: CMD
will provide it for you to the ENTRYPOINT
docker-entrypoint.sh
. 如果你没有在mongod
之后传递任何参数,你也不必输入mongod
: CMD
将为你提供ENTRYPOINT
docker-entrypoint.sh
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.