无法访问docker hostet mongo副本集

时间:2018-04-24 07:32:18

标签: node.js mongodb docker mongoose replicaset

我的撰写文件:

version: '3'
services:
  mongo-1:
    image: mongo:latest
    volumes:
      - ./data/1/:/data/db
    ports:
      - "30001:27017"
    restart: always
    container_name: mongo-cluster-1
    command: mongod --replSet mongo-cluster-dev
  mongo-2:
    image: mongo:latest
    volumes:
      - ./data/2/:/data/db
    ports:
      - "30002:27017"
    restart: always
    container_name: mongo-cluster-2
    command: mongod --replSet mongo-cluster-dev
  mongo-3:
    image: mongo:latest
    volumes:
      - ./data/3/:/data/db
    ports:
      - "30003:27017"
    restart: always
    container_name: mongo-cluster-3
    command: mongod --replSet mongo-cluster-dev
networks:
  default:
    external:
      name: mongo-cluster-dev

我的群集配置:

config = {
  "_id" : "mongo-cluster-dev",
  "members" : [{
    "_id" : 0,
    "host" : "mongo-1:27017"
  },
  {
    "_id" : 1,
    "host" : "mongo-2:27017"
  },
  {
  "_id" : 2,
  "host" : "mongo-3:27017"
  }]
}

配置没有问题。我无法通过192.168.21.155:30001(3)从外部访问3个数据库中的任何一个但是当我正在尝试与猫鼬连接时:

mongoose.connect("mongodb://192.168.21.155:30001,192.168.21.155:30002,192.168.21.155:30003/test?replicaSet=mongo-cluster-dev")

我收到以下错误:

  

MongoNetworkError:无法连接到服务器[mongo-1:27017]   首先连接[MongoNetworkError:getaddrinfo ENOTFOUND mongo-1   蒙戈-1:27017]

这似乎是dns的问题?但是当我在配置中使用外部IP和发布端口时,配置失败。

0 个答案:

没有答案