docker-compose MongoDB错误:尝试在主机上运行命令“ isMaster”时出现网络错误 [英] docker-compose MongoDB Error: network error while attempting to run command 'isMaster' on host
本文介绍了docker-compose MongoDB错误:尝试在主机上运行命令“ isMaster”时出现网络错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用mongo从外部连接到docker容器中的mongodb,但出现以下错误。
I`m trying to connect to mongodb in docker container from outside with mongo, but I get the following error.
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存在问题,但我不明白。
When I bash into the Container everything is fine. It was working maybe half a year ago but now it won't. I think it's a problem with docker-compose, but I don't get it.
shell和服务器的版本相同。
为了测试,这是我的docker-compose.yaml
The versions of the shell and server are the same. For testing this is my 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
这篇关于docker-compose MongoDB错误:尝试在主机上运行命令“ isMaster”时出现网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文