Skip to content

Instantly share code, notes, and snippets.

@qknow-w
Forked from jmlrt/docker-compose.yml
Last active October 12, 2020 10:20
Show Gist options
  • Save qknow-w/9f9fac92ce71e15080f6a2c4c3e5fe1f to your computer and use it in GitHub Desktop.
Save qknow-w/9f9fac92ce71e15080f6a2c4c3e5fe1f to your computer and use it in GitHub Desktop.
MongoDB Replica Set with Docker
version: '2'
services:
mongo1:
container_name: mongo1
image: daocloud.io/mongo
ports:
- 27017:27017
expose:
- 27017
networks:
- mongo
command: mongod --replSet rs0 --smallfiles --oplogSize 128
mongo2:
container_name: mongo2
image: daocloud.io/mongo
expose:
- 27017
networks:
- mongo
command: mongod --replSet rs0 --smallfiles --oplogSize 128
mongo3:
container_name: mongo3
image: daocloud.io/mongo
expose:
- 27017
networks:
- mongo
command: mongod --replSet rs0 --smallfiles --oplogSize 128
networks:
mongo:
driver: bridge
@qknow-w
Copy link
Author

qknow-w commented Dec 6, 2017

master

db.createUser(
{
    user: "xxx",
    pwd: "xxx",
    roles: [ "root" ]
})
docker exec -it mongo1 mongo
connecting to: test
> rs.initiate()
> rs.add("mongo2:27017")
> rs.add("mongo3:27017") 
> rs.status();

secondary

 rs.slaveOk();

http://www.jianshu.com/p/4d86e9c33e0d

http://shellfu.com/setting-up-a-mongodb-replica-set-on-docker/

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