I am trying to create local setup of mongo with 3 repilca nodes
I have create docker compose file which contains 3 mongo nodes.
but when i am unable to connect to mongo with compass, its throwing ENOTFOUND errror.
mongo connection string -
mongodb://localhost:27017/
mongodb://mongo1:27017/
mongodb://:27017/
version: '3'
services:
mongo1:
image: mongo:4.4
container_name: mongo1
ports:
- "27017:27017"
networks:
- elk-net
volumes:
- ./data/mongo1:/data/db
command: mongod --replSet rs0 --bind_ip_all
mongo2:
image: mongo:4.4
container_name: mongo2
ports:
- "27018:27017"
networks:
- elk-net
volumes:
- ./data/mongo2:/data/db
command: mongod --replSet rs0 --bind_ip_all
mongo3:
image: mongo:4.4
container_name: mongo3
ports:
- "27019:27017"
networks:
- elk-net
volumes:
- ./data/mongo3:/data/db
command: mongod --replSet rs0 --bind_ip_all
networks:
elk-net:
You can find below a working solution for MongoDB replica set (It contains 2 replicas). The docker-compose.yml has several useful comments.
docker-compose.yml:
docker-entrypoint-mongo.sh:
The connection string for MongoDB replica-set: