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.
rs.initiate()
?