Skip to content

Instantly share code, notes, and snippets.

@jmlrt
Created February 18, 2016 07:22
Show Gist options
  • Save jmlrt/7f50cdd5464485f65e9b to your computer and use it in GitHub Desktop.
Save jmlrt/7f50cdd5464485f65e9b to your computer and use it in GitHub Desktop.
MongoDB Replica Set with Docker
version: '2'
services:
mongo1:
container_name: mongo1
image: mongo:2.4
expose:
- 27017
networks:
- mongo
command: mongod --replSet rs0 --smallfiles --oplogSize 128
mongo2:
container_name: mongo2
image: mongo:2.4
expose:
- 27017
networks:
- mongo
command: mongod --replSet rs0 --smallfiles --oplogSize 128
mongo3:
container_name: mongo3
image: mongo:2.4
expose:
- 27017
networks:
- mongo
command: mongod --replSet rs0 --smallfiles --oplogSize 128
networks:
mongo:
driver: bridge
@jmlrt
Copy link
Author

jmlrt commented Feb 18, 2016

Commands to run to initiate RS:

docker exec -it mongo1 mongo
connecting to: test
> rs.initiate()
> cfg = rs.conf()
> cfg.members[0].host = "mongo1:27017"
> rs.reconfig(cfg)
> rs.add("mongo2:27017")
> rs.add("mongo3:27017") 
> rs.status();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment