docker安装副本集MongoDB

拉取镜像

docker pull mongo

安装

docker run --name m0 -p 27017:27017 -d mongo:latest --replSet "rs"
docker run --name m1 -p 27017:27017 -d mongo:latest --replSet "rs"
docker run --name m2 -p 27017:27017 -d mongo:latest --replSet "rs"

进入镜像

docker exec -it m0 bash

执行

mongo
docker安装副本集MongoDB_第1张图片

show dbs;
日志如下
2019-04-26T03:46:11.527+0000 E QUERY [js] Error: listDatabases failed:{
“operationTime” : Timestamp(0, 0),
“ok” : 0,
“errmsg” : “not master and slaveOk=false”,
“code” : 13435,
“codeName” : “NotMasterNoSlaveOk”,
“$clusterTime” : {
“clusterTime” : Timestamp(1556248153, 1),
“signature” : {
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),
“keyId” : NumberLong(0)
}
}
} :

执行

rs.slaveOk();

show dbs;

use admin

执行关联操作看下图

var config={_id:"rs",members:[{_id:0,host:"172.17.0.7:27017"},{_id:1,host:"172.17.0.7:37017"},{_id:2,host:"172.17.0.7:47017"}]};

rs.initiate(config)

use admin

db.createUser( { user: "root",  pwd: "root",  roles: [ { role: "root", db: "admin" } ] } );

docker安装副本集MongoDB_第2张图片

你可能感兴趣的:(mongo,MongoDB)