在Docker容器中初始化MongoDB副本集时出错

我用这个命令创build了一个带有副本集的MongoDB docker容器:

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

容器开始运行。

然后我尝试使用以下命令启动副本集:

 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 } 

但它给出了错误消息“ 已经初始化 ”。

当我用rs.status()命令检查副本集的健康状况时

 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 } 

它说副本集configuration是无效的。

看起来你没有指定任何副本集configuration。

复制集启动示例 :

  rs.initiate( { _id: "myReplSet", version: 1, members: [ { _id: 0, host : "mongodb0.example.net:27017" }, { _id: 1, host : "mongodb1.example.net:27017" }, { _id: 2, host : "mongodb2.example.net:27017" } ] } )