docker compose MongoDB错误:尝试运行命令时出现网络错误';伊斯马斯特&x27;在主机上

docker compose MongoDB错误:尝试运行命令时出现网络错误';伊斯马斯特&x27;在主机上,mongodb,docker,docker-compose,Mongodb,Docker,Docker Compose,我正试图用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

我正试图用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\u ip\u all

所以 更改:

致:


我也有过类似的问题。在我的例子中,脚本首先启动docker,然后使用mongo.exe连接到它


解决方案是在mongo.exe连接并开始执行查询之前引入3秒睡眠。另一个解决方法是不将docker ip绑定到特定的本地ip,并允许从所有ip进行访问。然而,这不是我的选择。

没有人有同样的问题吗?
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