Created
December 14, 2023 15:14
-
-
Save Stoffo/d86c1481eef49653b5d604da7c054deb to your computer and use it in GitHub Desktop.
MongoDb ReplicaSet with Docker
This file contains 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
version: '3.8' | |
services: | |
mongo1: | |
image: mongo:latest | |
container_name: mongo1 | |
networks: | |
- mongo-net | |
ports: | |
- "27017:27017" | |
links: | |
- mongo2 | |
- mongo3 | |
volumes: | |
- ./data/db1:/data/db | |
command: --replSet rs0 | |
mongo2: | |
image: mongo:latest | |
container_name: mongo2 | |
networks: | |
- mongo-net | |
ports: | |
- "27018:27017" | |
volumes: | |
- ./data/db2:/data/db | |
command: --replSet rs0 | |
mongo3: | |
image: mongo:latest | |
container_name: mongo3 | |
networks: | |
- mongo-net | |
ports: | |
- "27019:27017" | |
volumes: | |
- ./data/db3:/data/db | |
command: --replSet rs0 | |
networks: | |
mongo-net: | |
driver: bridge |
This file contains 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
#!/bin/bash | |
docker-compose up -d | |
# Initiliaze ReplicaSet | |
docker exec -it mongo1 mongo --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'mongo1:27017'}, {_id: 1, host: 'mongo2:27017'}, {_id: 2, host: 'mongo3:27017'}]})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment