MongoDB Shard Cluster

37 views Asked by At

Good day people .Am having some trouble adding initiating replicas using the rs.initiate(). below is my docker-compose file

version: '3'
services:
  configs1:
    container_name: configs1
    image: mongo:6.0-focal
    command:
      - /bin/sh
      - -c
      - |
        mongod --keyFile /data/keyFile --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
    ports:
      - 10001:27017
    volumes:
      - ./keyFile:/data/keyFile
      - configs1:/data/db
    
  configs2:
    container_name: configs2
    image: mongo:6.0-focal
    command:
      - /bin/sh
      - -c
      - |
        mongod --keyFile /data/keyFile --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
    ports:
      - 10002:27017
    volumes:
      - ./keyFile:/data/keyFile
      - configs2:/data/db
    

  configs3:
    container_name: configs3
    image: mongo:6.0-focal
    command:
      - /bin/sh
      - -c
      - |
        mongod --keyFile /data/keyFile --configsvr --replSet cfgrs --port 27017 --dbpath /data/db  
    ports:
      - 10003:27017
    volumes:
      - ./keyFile:/data/keyFile
      - configs3:/data/db
   

volumes:
  configs1:
  configs2:
  configs3:

But when I try to access the docker container interactively and the use mongosh to access the DB. When I try

rs.initiate(
  {
    _id: "cfgrs",
    configsvr: true,
    members: [
      { _id : 0, host : "my-ip-address:10001" },
      { _id : 0, host : "my-ip-address:10002" },
    ]
  }
);

I get the following error MongoServerError: No host described in new configuration with {version: 1, term: 0} for replica set cfgrs maps to this node what could be the problem. Any help will be highly appreciated

I have tried using my docker ip address but it still bring that error.

0

There are 0 answers