【发布时间】:2020-08-19 23:41:39
【问题描述】:
我需要你的帮助, 我使用自定义示例配置文件创建了三个 docker MongoDB 容器,然后我需要为这些容器实现副本集,但我无法实现,我无法访问其他容器 IP 和端口
db.yaml
storage:
dbPath: /data/db
journal:
enabled: true
replication:
replSetName: "my_replicaSet"
net:
bindIp: 127.0.0.1
port: 26017
db1.yaml
storage:
dbPath: /data/db
journal:
enabled: true
replication:
replSetName: "my_replicaSet"
net:
bindIp: 127.0.0.1
port: 28017
db2.yaml
storage:
dbPath: /data/db
journal:
enabled: true
replication:
replSetName: "my_replicaSet"
net:
bindIp: 127.0.0.1
port: 29017
首先使用以下命令创建了三个 docker 容器
容器名称:数据库
docker run --name DB -v /home/mahesh/Documents/Trishula/cortana/database:/etc/mongo --net my-mongo-cluster -d mongo --config /etc/mongo/db.yaml
容器名称:DB1
docker run --name DB -v /home/mahesh/Documents/Trishula/cortana/database:/etc/mongo --net my-mongo-cluster -d mongo --config /etc/mongo/db1.yaml
容器名称:DB2
docker run --name DB -v /home/mahesh/Documents/Trishula/cortana/database:/etc/mongo --net my-mongo-cluster -d mongo --config /etc/mongo/db2.yaml
然后使用 mongo --port 26017 打开一个 docker 容器 DB shell
使用rs.initiate() 发起副本集
然后通过定义 rs.add("DB1") 将另一个 docker 容器作为成员添加到该 shell,这里 DB1 是另一个容器的名称,我收到这样的错误消息
my_replicaSet:PRIMARY> rs.add("DB1")
{
"operationTime" : Timestamp(1597812494, 1),
"ok" : 0,
"errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2",
"code" : 103,
"codeName" : "NewReplicaSetConfigurationIncompatible",
"$clusterTime" : {
"clusterTime" : Timestamp(1597812494, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
我也尝试使用 YAML 文件中定义的容器端口和 IP 地址,
my_replicaSet:PRIMARY> rs.add("127.0.0.1:28017")
{
"operationTime" : Timestamp(1597812984, 1),
"ok" : 0,
"errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: 127.0.0.1:26017; the following nodes did not respond affirmatively: 127.0.0.1:28017 failed with Error connecting to 127.0.0.1:28017 :: caused by :: Connection refused",
"code" : 74,
"codeName" : "NodeNotFound",
"$clusterTime" : {
"clusterTime" : Timestamp(1597812984, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
我已经使用命令行实现了副本集,但是我无法使用带有 docker MongoDB 容器的自定义 MongoDB 配置 YAML 文件来实现副本集,请帮助,我过去一周一直在研究这个......
注意:我没有使用 docker-compose YAML 文件...
【问题讨论】:
-
你在关注什么文档?
-
为了将自定义 MongoDB 配置文件设置为 Docker 容器,我遵循了这个官方文档 [hub.docker.com/_/mongo]