Last active
May 31, 2016 23:28
-
-
Save fernaspiazu/c0a3ac3a033710469effdd3174785f93 to your computer and use it in GitHub Desktop.
Build and configure a replica set environment with MongoDB
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: '2' | |
services: | |
shard00_rs0_mongod: | |
image: mongo | |
restart: always | |
container_name: shard00_rs0_mongod | |
volumes: | |
- shard00_rs0_data:/data/db | |
networks: | |
- shard00 | |
command: --replSet "shard00ReplSet" --smallfiles --oplogSize 128 --rest | |
shard00_rs1_mongod: | |
image: mongo | |
restart: always | |
container_name: shard00_rs1_mongod | |
volumes: | |
- shard00_rs1_data:/data/db | |
networks: | |
- shard00 | |
command: --replSet "shard00ReplSet" --smallfiles --oplogSize 128 --rest | |
shard00_rs2_mongod: | |
image: mongo | |
restart: always | |
container_name: shard00_rs2_mongod | |
networks: | |
- shard00 | |
volumes: | |
- shard00_rs2_data:/data/db | |
command: --replSet "shard00ReplSet" --smallfiles --oplogSize 128 --rest | |
networks: | |
shard00: | |
driver: bridge | |
volumes: | |
shard00_rs0_data: | |
shard00_rs1_data: | |
shard00_rs2_data: |
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
# Move to the docker-compose's directory | |
cd /path/to/docker-compose.yml | |
# Start services, create networks and volumes | |
docker-compose up -d | |
# Stop and delete services and drop networks | |
docker-compose down | |
# Stop and delete services, drop networks and volumes | |
docker-compose down -v | |
echo "Enjoy it :-)" |
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
# Open a mongo shell and copy/past the rs_initiate script | |
docker run -it --rm --net shard00_shard00 --name mongo-shell mongo sh -c 'exec mongo "shard00_rs1_mongod:27017/test"' |
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
rs.initiate( | |
{ | |
"_id": "shard00ReplSet", | |
"version": 1, | |
"members": [ | |
{ "_id": 0, "host" : "shard00_rs0_mongod:27017" }, | |
{ "_id": 1, "host" : "shard00_rs1_mongod:27017" }, | |
{ "_id": 2, "host" : "shard00_rs2_mongod:27017", "arbiterOnly": true } | |
] | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment