Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
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.

but when I see the dockerfile of mongodb, I'm confused, the entrypoint and cmd part of its dockerfile:

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? Won't it be docker-entrypoint.sh --auth? since the --auth will replace mongod, so why I run docker run mongo --auth but it works fine?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The mongod Dockerfile references docker-entrypoint.sh.
That script docker-entrypoint.sh starts by testing if the first parameter begins with '-' (as in '--auth'):

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

So the arguments become mongod --auth, not just --auth.

Meaning:

  • if you have to pass any argument after mongod, you don't have to type mongod first when using docker run: it will be added for you in docker-entrypoint.sh
  • if you don't have any argument to pass after mongod, you don't have to type mongod either: CMD will provide it for you to the ENTRYPOINT docker-entrypoint.sh.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda