Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
monog db replicate with docker compose
version: "3"
services:
mongo1:
image: mvertes/alpine-mongo
restart: always
ports:
- "27017:27017"
entrypoint: [ "/usr/bin/mongod", "--port", "27017", "--bind_ip_all", "--replSet", "rs"]
mongo2:
image: mvertes/alpine-mongo
restart: always
ports:
- "27018:27018"
entrypoint: [ "/usr/bin/mongod", "--port", "27018", "--bind_ip_all", "--replSet", "rs"]
mongo3:
image: mvertes/alpine-mongo
restart: always
ports:
- "27019:27019"
entrypoint: [ "/usr/bin/mongod", "--port", "27019", "--bind_ip_all", "--replSet", "rs"]
@smileboywtu

This comment has been minimized.

Copy link
Owner Author

@smileboywtu smileboywtu commented Apr 1, 2019

#!/bin/sh

sudo docker-compose -f docker-compose.yaml up -d
sudo docker-compose -f docker-compose.yaml exec mongo1 mongo --port 27017 --eval 'var cfg = { "_id": "rs", "version": 1, "members": [{ "_id": 0, "host": "mongo1:27017", "priority": 2 }, { "_id": 1, "host": "mongo2:27018", "priority": 0 }, { "_id": 2, "host": "mongo3:27019", "priority": 0 } ] }; rs.initiate(cfg); rs.status();
@smileboywtu

This comment has been minimized.

Copy link
Owner Author

@smileboywtu smileboywtu commented Apr 1, 2019

需要设置hosts:

127.0.0.1 mongo1
127.0.0.1 mongo2
127.0.0.1 mongo3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.