this is my first question here on Stackoverflow. I have recently created MongoDB replicaSet using Docker, I was doing that on Ubuntu, but when I cloned my repository on Windows it does not work. This is my docker-compose.yaml:
services:
mongo1:
container_name: mongo1
image: mongo:6
volumes:
- volMongo1:/data/db
- ./rs-init.sh:/scripts/rs-init.sh
networks:
- mongoNetwork
ports:
- 27017:27017
links:
- mongo2
- mongo3
restart: always
entrypoint:
["/usr/bin/mongod", "--bind_ip_all", "--replSet", "mongoReplicaSet"]
mongo2:
container_name: mongo2
image: mongo:6
volumes:
- volMongo2:/data/db
networks:
- mongoNetwork
ports:
- 27018:27017
restart: always
entrypoint:
["/usr/bin/mongod", "--bind_ip_all", "--replSet", "mongoReplicaSet"]
mongo3:
container_name: mongo3
image: mongo:6
volumes:
- volMongo3:/data/db
networks:
- mongoNetwork
ports:
- 27019:27017
restart: always
entrypoint:
["/usr/bin/mongod", "--bind_ip_all", "--replSet", "mongoReplicaSet"]
networks:
mongoNetwork:
volumes:
volMongo1:
volMongo2:
volMongo3:
and my script for replicaSet configuration:
#!/bin/bash
mongosh <<EOF
var config = {
"_id": "mongoReplicaSet",
"version": 1,
"members": [
{
"_id": 1,
"host": "mongo1:27017",
"priority": 3
},
{
"_id": 2,
"host": "mongo2:27018",
"priority": 2
},
{
"_id": 3,
"host": "mongo3:27019",
"priority": 1
}
]
}
rs.initiate(config, { force: true });
rs.status();
EOF
Docker works fine, I can get access to each instance of DB in the container. But when I try to initialize ReplicaSet I get this error:
MongoServerError[NodeNotFound]: replSetInitiate quorum check failed because not all proposed set members responded affirmatively: mongo2:27018 failed with Error connecting to mongo2:27018 (172.19.0.2:27018) :: caused by :: Connection refused, mongo3:27019 failed with Error connecting to mongo3:27019 (172.19.0.3:27019) :: caused by :: Connection refused
I do not know where this IP adress 172.19.0.3 come from and how can I change it. Maybe someone here coud help me?
I tried to change etc/hosts file to 127.0.0.1 mongo1 mongo2 mongo3, but it didn’t work.
Joanna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.