0

I am trying to create a mongo sharded cluster. First of all, I want to create a config server replica set with docker compose.

My docker-compose.yml file

version: "3.8"

services:
  mongo1:
    image: mongo
    container_name: mongo1
    ports:
      - 30001:27017
    restart: always
    entrypoint:
      [
        "/usr/bin/mongod",
        "--configsvr",
        "--replSet",
        "mongo-csrs",
        "--bind_ip_all",
        "--dbpath",
        "/data/db",
      ]
    volumes:
      - ./test-volume:/data/db

When I am trying to connect to mongod instance with this command: docker exec -it mongo1 mongosh

I get this error:

MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

However, if I remove "--configsvr" option from docker compose file and re-create docker container with docker compose command, I can successfully connect to mongod in the docker do whatever I need.

Can anyone give me a hint of what I am doing wrong and how to connect to a mongo instance in the docker, started with --configsvr flag?

PS: I am using the official doc to run mongod.

I am expecting to connect to mongod instance without any errors.

2
  • Where does it run the rs.initiate()? Commented Apr 15, 2024 at 20:40
  • The mongod log should give some clue what is going on
    – Joe
    Commented Apr 16, 2024 at 17:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.