Skip to content

Instantly share code, notes, and snippets.

@etsuo
Last active September 5, 2019 11:00
Show Gist options
  • Save etsuo/463304bd562af8ff18b32aff538b6cbe to your computer and use it in GitHub Desktop.
Save etsuo/463304bd562af8ff18b32aff538b6cbe to your computer and use it in GitHub Desktop.
docker-config.yml MongoDB replica set
version: "3"
services:
mongo1:
container_name: cf_mongo1
image: mongo:latest
ports:
- "127.0.0.1:37001:27017"
networks:
- backend
command: |
/bin/bash -c "
set -e
(mongod --replSet "rs" --bind_ip localhost,mongo1) &
while ! mongo --host mongo1:27017 --eval 'db.stats()'; do sleep 1 ; done
while ! mongo --host mongo2:27017 --eval 'db.stats()'; do sleep 1 ; done
while ! mongo --host mongo3:27017 --eval 'db.stats()'; do sleep 1 ; done
mongo --eval 'rs.initiate()'
mongo --eval 'rs.add(\"mongo2\")'
mongo --eval 'rs.add(\"mongo3\")'
mongo --eval 'rs.config()'
wait
"
mongo2:
container_name: cf_mongo2
image: mongo:latest
ports:
- "127.0.0.1:37002:27017"
networks:
- backend
command: mongod --replSet "rs" --bind_ip localhost,mongo2
mongo3:
container_name: cf_mongo3
image: mongo:latest
ports:
- "127.0.0.1:37003:27017"
networks:
- backend
command: mongod --replSet "rs" --bind_ip localhost,mongo3
networks:
backend:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment