Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
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?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

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.
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!