Created
December 19, 2024 23:47
-
-
Save majirieyowel/168aa2dd4705d355c9d129ce18aa3921 to your computer and use it in GitHub Desktop.
Setup a mongodb replicaset using docker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
mongo1: | |
image: mongo:5 | |
container_name: mongo1 | |
ports: | |
- 27017:27017 | |
networks: | |
- mongoCluster | |
command: > | |
mongod --replSet myReplicaSet --bind_ip localhost,mongo1 | |
mongo2: | |
image: mongo:5 | |
container_name: mongo2 | |
ports: | |
- 27018:27017 | |
networks: | |
- mongoCluster | |
command: > | |
mongod --replSet myReplicaSet --bind_ip localhost,mongo2 | |
mongo3: | |
image: mongo:5 | |
container_name: mongo3 | |
ports: | |
- 27019:27017 | |
networks: | |
- mongoCluster | |
command: > | |
mongod --replSet myReplicaSet --bind_ip localhost,mongo3 | |
initiate-replica: | |
image: mongo:5 | |
depends_on: | |
- mongo1 | |
- mongo2 | |
- mongo3 | |
networks: | |
- mongoCluster | |
entrypoint: > | |
bash -c " | |
sleep 5 && | |
mongosh --host mongo1 --eval \" | |
rs.initiate({ | |
_id: 'myReplicaSet', | |
members: [ | |
{ _id: 0, host: 'mongo1' }, | |
{ _id: 1, host: 'mongo2' }, | |
{ _id: 2, host: 'mongo3' } | |
] | |
}) | |
\" && | |
tail -f /dev/null | |
" | |
networks: | |
mongoCluster: | |
driver: bridge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment