Home:ALL Converter>Error initialising MongoDB replica set in Docker container

Error initialising MongoDB replica set in Docker container

Ask Time:2016-09-07T02:13:22         Author:sudhakar sudha

Json Formatter

I have created a MongoDB docker container, with a replica set, using this command:

docker run -d --name mongo -v /data/db:/data/db mongo --replSet name

The container starts running.

I then try to initiate the replica set, using this command:

rs.initiate()
{
    "info2" : "no configuration specified. Using a default configuration for the set",
    "me" : "fa07bcdd8591:27017",
    "info" : "try querying local.system.replset to see current configuration",
    "ok" : 0,
    "errmsg" : "already initialized",
    "code" : 23
}

But it gives the error message "already initialized".

When I check the health of the replica set with the rs.status() command

rs.status()
{
    "state" : 10,
    "stateStr" : "REMOVED",
    "uptime" : 102,
    "optime" : {
        "ts" : Timestamp(1472680081, 1),
        "t" : NumberLong(77)
    },
    "optimeDate" : ISODate("2016-08-31T21:48:01Z"),
    "ok" : 0,
    "errmsg" : "Our replica set config is invalid or we are not a member of it",
    "code" : 93
}

It says the replica set config is invalid.

Author:sudhakar sudha,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/39355357/error-initialising-mongodb-replica-set-in-docker-container
yy