gpt4 book ai didi

mongodb - docker-compose MongoDB 错误 : network error while attempting to run command 'isMaster' on host

转载 作者:行者123 更新时间:2023-12-02 18:44:38 30 4
gpt4 key购买 nike

我正在尝试使用 mongo 从外部连接到 docker 容器中的 mongodb,但出现以下错误。

MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2018-05-30T14:54:13.950+0200 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

当我猛击容器时,一切都很好。
也许半年前它可以工作,但现在不行了。
我认为这是 docker-compose 的问题,但我不明白。

shell 和服务器的版本是一样的。
为了测试这是我的 docker-compose.yaml
version: '3'
networks:
backend:
external:
name: my-mongo-cluster

services:

## Config Servers
config01:
image: mongo
command: mongod --port 27017 --configsvr --replSet configserver --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

config02:
image: mongo
command: mongod --port 27017 --configsvr --replSet configserver --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

config03:
image: mongo
command: mongod --port 27017 --configsvr --replSet configserver --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

## Shards
shard01a:
image: mongo
command: mongod --port 27018 --shardsvr --replSet shard01 --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

shard01b:
image: mongo
command: mongod --port 27018 --shardsvr --replSet shard01 --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

shard02a:
image: mongo
command: mongod --port 27019 --shardsvr --replSet shard02 --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

shard02b:
image: mongo
command: mongod --port 27019 --shardsvr --replSet shard02 --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

shard03a:
image: mongo
command: mongod --port 27020 --shardsvr --replSet shard03 --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend

shard03b:
image: mongo
command: mongod --port 27020 --shardsvr --replSet shard03 --noprealloc --smallfiles --oplogSize 16
volumes:
- ./scripts:/scripts
networks:
- backend


## Router
router:
image: mongo
command: mongos --port 27017 --configdb configserver/config01:27017,config02:27017,config03:27017
ports:
- "27017:27017"
volumes:
- ./scripts:/scripts
networks:
- backend
depends_on:
- config01
- config02
- config03
- shard01a
- shard01b
- shard02a
- shard02b
- shard03a
- shard03b

最佳答案

我有同样的问题
我通过向 mongos 添加以下关键字来解决它: --bind_ip_all

所以
改变:

mongos --port 27017 --configdb configserver/config01:27017,config02:27017,config03:27017 

到:
 mongos --bind_ip_all --port 27017 --configdb configserver/config01:27017,config02:27017,config03:27017

关于mongodb - docker-compose MongoDB 错误 : network error while attempting to run command 'isMaster' on host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50605575/

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