0

How does the ENTRYPOINT command works given in the below docker compose file. I have found the docker compose file in replica Set mongo docker-compose. "usr/bin/mongod" is the first command given in the ENTRYPOINT, my Question is whether the usr/bin/mongod will start the local mongo and run it has docker container or it will pull the mongo image from repository and run it as container if so why we are using "usr/bin/mongod".

version: "3"
services:
  mongo-1:
    hostname: mongo-1
    container_name: mongo-1
    image: mongo:4.0
    ports:
      - "127.0.0.1:28000:28000"
    volumes:
      - ./mongo-1/data:/data/db
    restart: always
    entrypoint: [ "/usr/bin/mongod", "--port", "28000", "--bind_ip_all", "--replSet", "rs1" ] 

using this compose file i am able to connect mongoDB running in the port 28000 from host machine but when i replace the ENTRYPOINT with CMD in the compose file i am not able to connect the mongoDB from host machine.

  • Possible duplicate of [What is the difference between CMD and ENTRYPOINT in a Dockerfile?](https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile) – jannis May 27 '19 at 08:47

1 Answers1

0

You are using the image "mongo:4.0" which has its own ENTRYPOINT and CMD defined. When you redeclare any of them in your docker-compose.yml then you are overwriting the original ones.

ENTRYPOINT is the main command and CMD are only parameters sent to the main command. For this reason it works for you when you define ENTRYPOINT with a valid command. If you change it to CMD then when is run is the original ENTRYPOINT ("docker-entrypoint.sh") and the new command.

Your entrypoint uses the binary from inside your container that is based on the specified image.

For reference you can see the Dockerfile of the official image: https://github.com/docker-library/mongo/blob/40056ae591c1caca88ffbec2a426e4da07e02d57/4.0/Dockerfile

The ENTRYPOINT and CMD are defined at the end.

Mihai
  • 9,526
  • 2
  • 18
  • 40