Starting MongoDB Replica Set on Docker

Why I published this

Today I was attending Docker Meetup at MongoDB. During one of the presentations there was a question about running MongoDB Replica Set using Docker. After returning home I decided to try if I can do this. I decided to publish it on Github so if anybody is having the same issues they can see my solution to have an idea how it could be implemented.


General Information

This file describes how to run Mongo DB Replica Set on Docker. We made an assumption that Docker IP address on host machine is 172.17.42.1 (and in most cases it's true). You can verify it by running ifconfig docker0 and checking ip address.

We're starting 3 docker containers with MongoDB, they are available on ports 27017, 27018 and 27019.

Instructions

Clone this repository

$ git clone git@github.com:klivan/docker-mongodb-replicaset.git
Build docker image from Dockerfile

$ cd docker-mongodb-replicaset
$ docker build -t mongo .
Start docker 3 containers with replica set

$ ./start.sh
Run one more Mongo docker container with bash

$ docker run -i -t mongo bash
And run script for Replica Set initialization:

$ ./replicaSet.sh
If you see an error during this step - please wait few minutes - most probably your docker containers haven't started yet. You'll see something like this:

root@e4216ca7766f:/# ./replicaSet.sh
MongoDB shell version: 2.6.8
connecting to: 172.17.42.1:27017/test
{
    "info" : "Config now saved locally.  Should come online in about a minute.",
    "ok" : 1
}
bye
You can verify that eveything works by running mongo client and checking rs.status():

root@29849b0f568c:/# mongo 172.17.42.1:27017
MongoDB shell version: 2.6.8
connecting to: 172.17.42.1:27017/test
rs0:PRIMARY> rs.status()
{
    "set" : "rs0",
    "date" : ISODate("2015-02-26T04:51:48Z"),
    "myState" : 1,
    "members" : [
        {
            "_id" : 0,
            "name" : "172.17.42.1:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 448,
            "optime" : Timestamp(1424925935, 1),
            "optimeDate" : ISODate("2015-02-26T04:45:35Z"),
            "electionTime" : Timestamp(1424925946, 1),
            "electionDate" : ISODate("2015-02-26T04:45:46Z"),
            "self" : true
        },
        {
            "_id" : 1,
            "name" : "172.17.42.1:27018",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 370,
            "optime" : Timestamp(1424925935, 1),
            "optimeDate" : ISODate("2015-02-26T04:45:35Z"),
            "lastHeartbeat" : ISODate("2015-02-26T04:51:47Z"),
            "lastHeartbeatRecv" : ISODate("2015-02-26T04:51:47Z"),
            "pingMs" : 0,
            "syncingTo" : "172.17.42.1:27017"
        },
        {
            "_id" : 2,
            "name" : "172.17.42.1:27019",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 370,
            "optime" : Timestamp(1424925935, 1),
            "optimeDate" : ISODate("2015-02-26T04:45:35Z"),
            "lastHeartbeat" : ISODate("2015-02-26T04:51:47Z"),
            "lastHeartbeatRecv" : ISODate("2015-02-26T04:51:47Z"),
            "pingMs" : 1,
            "syncingTo" : "172.17.42.1:27017"
        }
    ],
    "ok" : 1
}
rs0:PRIMARY>

Comments

  1. Anonymous4:34 PM

    Casino Web App - deccasino.com
    Enjoy dafabet link the latest casino web mobile app for real money & 카지노사이트 free 온카지노 to bet online, mobile, and tablet without downloading. You'll also benefit from various promotions

    ReplyDelete
  2. We even have boosted odds on all sports you can to|you probably can} think of, from soccer to golf to e-sports, any sport you may be excited about. Gaming companies provide constant provides of “risk-free” bets, which permit prospects to guess a lot as} a certain amount|a particular amount|a certain quantity}; occasion that they} lose, the money is returned to them as a credit that they can use to guess later. They open an app from a myriad of gaming companies and guess on just about anything you can to|you probably can} think about, together with darts, snooker, Australian rules soccer and handball, 코인카지노 before and during video games. It’s reminiscent of to|paying homage to} the January 2021 technology-fueled stock-market run of GameStop, which was promoted on social media and joined online by scads of profit-seeking young traders. And the possibility to play parlays, place prop bets (will James Harden make more than 2.5 three-pointers in opposition to the Heat?), and wager during video games is extraordinarily attractive to people 21 to 30 years old. Cash Out betting functionality lets the user of a betting web site take profit early if their guess is coming in, or get a few of their stake back if their guess goes in opposition to them—all before the event is over.

    ReplyDelete

Post a Comment

Popular posts from this blog