Home > Enterprise >  docker compose set mongodb bindIp to 0.0.0,0 in /etc/mongod.conf
docker compose set mongodb bindIp to 0.0.0,0 in /etc/mongod.conf

Time:10-18

I have the following mongo-compose file:

version: '3.8'

services:
  mongo3:
    container_name: mongo3
    image: mongo:4.4

    volumes:
      - ~/mongos/data3:/data/db
    networks:
      - mongo-network
    ports:
      - 27017:27017
    restart: always        
    command: --replSet "rs1" --bind_ip 0.0.0.0

networks:
  mongo-network:
    driver: bridge

My objective is to edit the file /etc/mongod.conf.orig in the container in such way that:

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  <----- I wish this to be 0.0.0.0


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:  <---------------- should be replication: replSetName: "rs1"

#sharding:

## Enterprise-Only Options:

#auditLog:

unfortunately the command in the docker-compose doesn't apply those changes. I have also tried:

entrypoint: [ "/usr/bin/mongod", "--bind_ip_all","0.0.0.0", "--replSet", "rs1" ]

but that doesn't allow the container to run.

CodePudding user response:

The dockerhub.com page for mongo states:

...

For example, /my/custom/mongod.conf is the path to the custom configuration file. Then start the MongoDB container like the following:

$ docker run --name some-mongo -v /my/custom:/etc/mongo -d mongo --config /etc/mongo/mongod.conf

...

Translated to the docker-compose.yml, this would mean we write something like:

version: '3.8'

services:
  mongo3:
    container_name: mongo3
    image: mongo:4.4

    volumes:
      - ~/mongos/data3:/data/db
      - ./mongo/config:/etc/mongo
    networks:
      - mongo-network
    ports:
      - 27017:27017
    restart: always        
    command: --config /etc/mongo/mongod.conf

networks:
  mongo-network:
    driver: bridge

We would then create a folder mongo/config within the directory containing the docker-compose.yml, and within the folder, we create the mongod.conf:

mkdir -p mongo/config && touch mongo/config/mongod.conf

We can then edit this file to our liking, e.g. setting the bind address and the replication name.

  • Related