容器之间的Docker Swarm连接因某些容器而被拒绝

时间:2017-04-30 05:47:58

标签: docker docker-machine docker-swarm

简化群:

manager1 node
    - consul-agent

worker1 node
    - consul-client1
    - web-app:80
    - web-network:9000

database1 node
    - consul-client2
    - redis:6379
    - mongo:27017

web-appweb-network服务可以通过其服务名称正确连接到redismongo,例如redis.createClient('6379', 'redis')mongoose.connect('mongodb://mongo')。< / p>

但是,容器web-app无法连接到web-network,我试图提出这样的请求:

request('http://web-network:9000')

但是得到错误:

errorno: ECONNREFUSED
address: 10.0.1.9
port: 9000

使用私有IP请求web-network确实有效:

request('http://11.22.33.44:9000')

我错过了什么?为什么他们可以连接到redismongo但不能连接到每个容器之间?将redis / mongo移动到与web-app相同的节点时,它仍然有效,因此我认为问题不会发生,因为服务无法与服务进行通信相同的服务器节点。

我们能否让docker网络使用私有IP而不是预先配置的子网?

docker stack deploy file

version: '3'
services:
  web-app:
    image: private-repo/private-image
    networks:
      - swarm-network
    ports:
      - "80:8080"
    deploy:
      placement:
        constraints:
          - node.role==worker
  web-network:
    image: private-repo/private-image2
    networks:
      - swarm-network
    ports:
      - "9000:8080"
    deploy:
      placement:
        constraints:
          - node.role==worker

  redis:
    image: redis:latest
    networks:
      - swarm-network
    ports:
      - "6739:6739"
    deploy:
      placement:
        constraints:
          - engine.labels.purpose==database

  mongo:
    image: mongo:latest
    networks:
      - swarm-network
    ports:
      - "27017:27017"
    deploy:
      placement:
        constraints:
          - engine.labels.purpose==database

networks:
  swarm-network:
    driver: overlay

docker stack deploy app -c docker-compose.yml

0 个答案:

没有答案