1. 程式人生 > >Docker overlay網絡互通

Docker overlay網絡互通

doc rap sta 圖片 oss advertise systemctl ridge 指定

1 yum install docker-ce -y yum install python-pip -y pip install docker-compose systemctl enable docker.service systemctl start docker.service docker pull progrium/consul 環境: 192.168.56.11 192.168.56.12 192.168.56.13 目的實現192.168.56.11 自建網絡互通 192.168.56.13 docker run -d -p 8500:8500 --name consul progrium/consul -server -bootstrap 192.168.56.11 /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H tcp://192.168.56.11 -H unix://var/run/docker.sock [root@linux-node1 ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["http://224ac393.m.daocloud.io"], "cluster-store": "consul://192.168.56.13:8500", "cluster-advertise": "192.168.56.11:2375" } [root@linux-node1 ~]# systemctl daemon-reload systemctl restart docker 192.168.56.12 /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H tcp://192.168.56.12 -H unix://var/run/docker.sock [root@linux-node1 ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["http://224ac393.m.daocloud.io"], "cluster-store": "consul://192.168.56.13:8500", "cluster-advertise": "192.168.56.12:2375" } [root@linux-node2 ~]# systemctl daemon-reload systemctl restart docker 瀏覽器瀏覽 測試 192.168.56.11 上面 docker network create -d overlay --subnet 192.168.1.0/24 ov_net1 #192.168.56.12 上面默認就有了 不用創建了 [root@linux-node1 ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 587ebbdc8cf6 bridge bridge local 42863825595a docker_gwbridge bridge local df6484f00517 host host local adf74519830e none null local e8d259aa8fe3 ov_net1 overlay global [root@linux-node1 ~]# [root@linux-node2 ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 624c4d1628bd bridge bridge local 4f7d45ab8d94 docker_gwbridge bridge local df6484f00517 host host local adf74519830e none null local e8d259aa8fe3 ov_net1 overlay global [root@linux-node2 ~]# 192.168.56.11測試 docker run -it --rm --net=ov_net1 busybox 192.168.56.12測試 docker run -it --rm --net=ov_net1 busybox 查看兩個容器的IP地址互相ping下 可以ping通 docker run -it --rm --net=ov_net1 --ip=192.168.1.10 busybox #指定IP地址

技術分享圖片

Docker overlay網絡互通