gpt4 book ai didi

mongodb - 无法连接到工作的Dockerized Mongo ReplSet

转载 作者:行者123 更新时间:2023-12-02 19:30:06 24 4
gpt4 key购买 nike

我正在尝试使用以下docker-compose文件创建在本地运行的Mongo ReplicaSet:

version: '2.0'

services:
db01:
image: mongo:3.4
mem_limit: 512m
restart: always
ports:
- "27017:27017"
volumes:
- datadb01:/data/db
- ./etc/mongod.conf:/etc/mongod.conf
command: mongod --smallfiles --noIndexBuildRetry --replSet rs0
container_name: db01
networks:
- mongo

db02:
image: mongo:3.4
mem_limit: 512m
restart: always
ports:
- "27018:27017"
volumes:
- datadb02:/data1/db
- ./etc/mongod.conf:/etc/mongod.conf
command: mongod --smallfiles --noIndexBuildRetry --replSet rs0
container_name: db02
networks:
- mongo

因此,这实际上似乎可行!我不会发布全部内容,但是当我运行 rs.status()时,我得到以下信息:
{
"set" : "rs0",
...
"ok" : 1
}

但是,当我尝试连接到copysetSet而不是单个节点时,会收到以下错误日志:
~/utils/infrastructure/content-repl-set [replay-content*]: mongo --host rs0/127.0.0.1:27017,127.0.0.1:27018
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017,127.0.0.1:27018/?replicaSet=rs0
2018-09-10T17:50:42.173-0400 I NETWORK [js] Starting new replica set monitor for rs0/127.0.0.1:27017,127.0.0.1:27018
2018-09-10T17:50:42.176-0400 I NETWORK [js] Successfully connected to 127.0.0.1:27018 (1 connections now open to 127.0.0.1:27018 with a 5 second timeout)
2018-09-10T17:50:42.177-0400 I NETWORK [js] changing hosts to rs0/db01:27017,db02:27017 from rs0/127.0.0.1:27017,127.0.0.1:27018
2018-09-10T17:50:42.177-0400 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to 127.0.0.1:27017 (1 connections now open to 127.0.0.1:27017 with a 5 second timeout)
2018-09-10T17:50:42.684-0400 W NETWORK [js] Unable to reach primary for set rs0

我的最佳猜测是mongo shell(以及其他mongo驱动程序,例如 pymongo)不知道我在docker容器中指定的容器名称。有没有办法将此信息公开给我的本地计算机?还是我记错了?谢谢你的帮助

最佳答案

您正在使用MacOS吗?如果是这样,似乎docker中的那些内部IP地址无法访问,因为docker(Linux)桥接网络无法从macOS主机访问。

此处更多信息:https://docs.docker.com/docker-for-mac/networking/

关于mongodb - 无法连接到工作的Dockerized Mongo ReplSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52266230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com