Reputation: 55
I tried to create a replica set with on my docker-compose file, the replica set members are up and running and i also can connect with mongosh -- and i can run rs.status().
But i cannot connect the mongoDB Compass with the connection string below.
When i tried to connect compass i got this error: getaddrinfo ENOTFOUND host.docker.internal
Here's my App Module which includes the connection string
'mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs0&serverSelectionTimeoutMS=2000',
{
maxStalenessSeconds: 120,
readPreference: 'secondaryPreferred',
},
)
Here's my docker-compose file:
services:
mongo1:
image: mongo:7.0
command: ['--replSet', 'rs0', '--bind_ip_all', '--port', '27017']
ports:
- 27017:27017
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'localhost:27017',priority:1},{_id:1,host:'localhost:27018',priority:0.5},{_id:2,host:'localhost:27019',priority:0.5}]}) }" | mongosh --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30
volumes:
- 'mongo1_data:/data/db'
- 'mongo1_config:/data/configdb'
mongo2:
image: mongo:7.0
command: ['--replSet', 'rs0', '--bind_ip_all', '--port', '27018']
ports:
- 27018:27018
volumes:
- 'mongo2_data:/data/db'
- 'mongo2_config:/data/configdb'
mongo3:
image: mongo:7.0
command: ['--replSet', 'rs0', '--bind_ip_all', '--port', '27019']
ports:
- 27019:27019
volumes:
- 'mongo3_data:/data/db'
- 'mongo3_config:/data/configdb'
volumes:
mongo1_data:
mongo2_data:
mongo3_data:
mongo1_config:
mongo2_config:
mongo3_config:
Upvotes: 0
Views: 194