Confused with CMD and ENTRYPOINT in docker file

I knew that in the docker file, when ENTRYPOINT and CMD are provided, the values ​​in the CMD will be the default parameter ENTRYPOINT, then when you start the container with the additional parameter, the additional parameter will replace the CMD values ​​in the dockerfile.

but when I see the mongodb docker file, I am confused by the entry point and cmd part of its docker file:

ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 27017
CMD ["mongod"]

I know when I started docker run mongo:latest, it will be docker-entrypoint.sh mongod, but when I started docker run mongo:latest --auth, why could it work correctly? Won't it be docker-entrypoint.sh --auth? because it --authreplaces mongod, so why am I running docker run mongo --auth, but it works fine?

+4
source share
1 answer

mongod Dockerfile docker-entrypoint.sh. < > script docker-entrypoint.sh , '-' ( '--auth'):

if [ "${1:0:1}" = '-' ]; then
    set -- mongod "$@"
fi

, mongod --auth, --auth.

:

  • mongod, mongod docker run: docker-entrypoint.sh
  • mongod, mongod : CMD ENTRYPOINT docker-entrypoint.sh.
+7

Source: https://habr.com/ru/post/1673755/


All Articles