Home:ALL Converter>What is the proper way of setting a mongodb replica set using docker and fig?

What is the proper way of setting a mongodb replica set using docker and fig?

Ask Time:2014-12-13T01:50:41         Author:Felipe Sabino

Json Formatter

What is the proper way of setting a mongodb replica set using docker and fig?

I was trying to follow official mongodb tutorials to create a fig.yml file with some replica sets but always got blocked by how to call rs.initiate() and rs.add("<hostname><:port>") properly.

I found this SO answer explaining why I can't start everything just from the shell, without calling rs.initiate(), so how can I accomplish that?

Oh, and I am using mongo:latest (v2.6.5) as base image, without any modifications.

Author:Felipe Sabino,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27449306/what-is-the-proper-way-of-setting-a-mongodb-replica-set-using-docker-and-fig
michael_erasmus :

I had a similar problem, this is what I did. I'm using docker-compose instead of fig. \n\nIn my docker-compose.\n\nmongors: \n image: mongo \n ports: \n - \"27017:27017\" \n volumes: \n - ./mongo:mongo \n entrypoint: mongo/entrypoint.sh\n\n\nIn my entrypoint.sh:\n\n#!/bin/bash\nmongod --port 27018 --replSet rs0 --fork --syslog --smallfiles\nmongo --port 27018 --eval \"rs.initiate({_id : 'rs0', members : [{_id : 0, host : 'localhost:27018'}]})\"\nmongo --port 27018 --eval \"while(true) {if (rs.status().ok) break;sleep(1000)};\"\n\n\nMake sure it's executable:\n\nchmod +x mongo/entrypoint.sh\n\n\nIt's a little hacky, but it works :)",
2015-06-29T14:05:39
yy