Forked from oleurud/local-mongo-replicaset-with-docker
Last active
December 2, 2017 08:59
-
-
Save rubenmromero/a0636d68bd019e341c59f46a7105d4f0 to your computer and use it in GitHub Desktop.
Bash :: Run local MongoDB Replica Set with Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pull the official mongo docker container | |
docker pull mongo | |
# create network | |
docker network create my-mongo-cluster | |
# create mongos | |
docker run -d --net my-mongo-cluster -p 27017:27017 --name mongo1 mongo mongod --replSet my-mongo-set --port 27017 | |
docker run -d --net my-mongo-cluster -p 27018:27018 --name mongo2 mongo mongod --replSet my-mongo-set --port 27018 | |
docker run -d --net my-mongo-cluster -p 27019:27019 --name mongo3 mongo mongod --replSet my-mongo-set --port 27019 | |
# add hosts | |
127.0.0.1 mongo1 mongo2 mongo3 | |
# setup replica set | |
docker exec -it mongo1 mongo | |
db = (new Mongo('localhost:27017')).getDB('test') | |
config={"_id":"my-mongo-set","members":[{"_id":0,"host":"mongo1:27017"},{"_id":1,"host":"mongo2:27018"},{"_id":2,"host":"mongo3:27019"}]} | |
rs.initiate(config) | |
# connection URI | |
mongodb://localhost:27017,localhost:27018,localhost:27019/{db}?replicaSet=my-mongo-set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment