无群的Docker领事集群

时间:2018-11-14 08:09:28

标签: docker docker-compose consul

由于公司的限制,我无法使用docker-swarm,因此我尝试在共享同一主机网络的多台计算机上设置领事群集,让我们假设这是3台计算机的地址(我将virtualbox与docker-machine一起用于测试),这些IP的容器称为HOST_IP

  • dm1 :192.168.99.100
  • dm2 :192.168.99.101
  • dm3 :192.168.99.102

CONSUL_BOOTSTRAP_IP是主要的领事引导服务器192.168.99.100

此设置有效(我在Web UI中启动并运行了3个节点),但是在容器中却得到了一些奇怪的日志:

consul-server_1_46f1167db7a9 |     2018/11/14 08:06:48 [WARN] consul: error getting server health from "64bbf570ff39": rpc error getting client: failed to get conn: dial tcp <nil>->172.18.0.2:8300: connect: no route to host
consul-server_1_46f1167db7a9 |     2018/11/14 08:06:50 [WARN] consul: error getting server health from "64bbf570ff39": context deadline exceeded
consul-server_1_46f1167db7a9 |     2018/11/14 08:06:51 [WARN] consul: error getting server health from "64bbf570ff39": rpc error getting client: failed to get conn: dial tcp <nil>->172.18.0.2:8300: connect: no route to host
consul-server_1_46f1167db7a9 |     2018/11/14 08:06:52 [WARN] consul: error getting server health from "64bbf570ff39": context deadline exceeded
consul-server_1_46f1167db7a9 |     2018/11/14 08:06:53 [WARN] consul: error getting server health from "64bbf570ff39": last request still outstanding
consul-server_1_46f1167db7a9 |     2018/11/14 08:06:54 [WARN] consul: error getting server health from "64bbf570ff39": rpc error getting client: failed to get conn: dial tcp <nil>->172.18.0.2:8300: connect: no route to host

为什么领事试图访问docker容器内部IP 172.18.0.*而不是使用-advertise地址?这很烦人,在用户界面中,我可以看到一些鬼节点的出现和消失以及错误状态。

这是我的撰写文件:

dm1

version: '2'

services:
    consul-server:
        image: consul:latest
        networks:
            - back
        command:
            agent
            -node consul-01
            -server
            -client 0.0.0.0
            -bootstrap-expect 3
            -ui
            -advertise ${HOST_IP}
        ports:
            - "8300:8300"
            - "8301:8301"
            - "8301:8301/udp"
            - "8302:8302"
            - "8302:8302/udp"
            - "8400:8400"
            - "8500:8500"
            - "8600:8600"
            - "8600:53/udp"

dm2

version: '2'

services:
    consul-server:
        image: consul:latest
        networks:
            - back
        command:
            agent
            -node consul-02
            -server
            -client 0.0.0.0
            -bootstrap-expect 3
            -retry-join ${CONSUL_BOOTSTRAP_IP}
            -advertise ${HOST_IP}
        ports:
            - "8300:8300"
            - "8301:8301"
            - "8301:8301/udp"
            - "8302:8302"
            - "8302:8302/udp"
            - "8400:8400"
            - "8500:8500"
            - "8600:8600"
            - "8600:53/udp"

dm3

version: '2'

services:
    consul-server:
        image: consul:latest
        networks:
            - back
        command:
            agent
            -node consul-03
            -server
            -client 0.0.0.0
            -bootstrap-expect 3
            -retry-join ${CONSUL_BOOTSTRAP_IP}
            -advertise ${HOST_IP}
        ports:
            - "8300:8300"
            - "8301:8301"
            - "8301:8301/udp"
            - "8302:8302"
            - "8302:8302/udp"
            - "8400:8400"
            - "8500:8500"
            - "8600:8600"
            - "8600:53/udp"

0 个答案:

没有答案