Skip to content

Instantly share code, notes, and snippets.

@boriphuth
Created May 29, 2019 07:49
Show Gist options
  • Save boriphuth/e3a4dc9475a803695bf2e735eb91f4e4 to your computer and use it in GitHub Desktop.
Save boriphuth/e3a4dc9475a803695bf2e735eb91f4e4 to your computer and use it in GitHub Desktop.
docker-compose mongodb replica
version: "3"
services:
mongo1:
hostname: mongo1
container_name: localmongo1
image: mongo:4.0-xenial
expose:
- 27017
ports:
- 27011:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
mongo2:
hostname: mongo2
container_name: localmongo2
image: mongo:4.0-xenial
expose:
- 27017
ports:
- 27012:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
mongo3:
hostname: mongo3
container_name: localmongo3
image: mongo:4.0-xenial
expose:
- 27017
ports:
- 27013:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
@boriphuth
Copy link
Author

$ docker exec -it localmongo1 mongo

config={_id:"rs0",members:[{_id:0,host:"mongo1:27017"},{_id:1,host:"mongo2:27017"},{_id:2,host:"mongo3:27017"}]};

rs.initiate(config);

rs.status();

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