1. 程式人生 > >從零開始學習docker(八)多臺機器通訊

從零開始學習docker(八)多臺機器通訊

上一節中,我們介紹了在同一個機器裡面同一個docker裡面不同的容器如何進行通訊的。這一節我們介紹如何在不同的Linux機器上面的容器通訊。

準備實驗環境:

docker node1 ip: 172.16.247.131  name:test1

docker node2 ip: 172.16.247.132 name:test2

在docker node1 上:

wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gz
nohup ./etcd --name docker-node1 --initial-advertise-peer-urls http://172.16.247.131:2380 \
--listen-peer-urls http://172.16.247.131:2380 \
--listen-client-urls http://172.16.247.131:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.247.131:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster docker-node1=http://172.16.247.131:2380,docker-node2=http://172.16.247.132:2380 \
--initial-cluster-state new&
./etcdctl cluster-health
member 72400c6f5c5691f3 is healthy: got healthy result from http://172.16.247.131:2379
member dc0810ee9a06524d is healthy: got healthy result from http://172.16.247.132:2379
cluster is healthy

在docker node2上:

wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gz
nohup ./etcd --name docker-node2 --initial-advertise-peer-urls http://172.16.247.132:2380 \
--listen-peer-urls http://172.16.247.132:2380 \
--listen-client-urls http://172.16.247.132:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.247.132:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster docker-node1=http://172.16.247.131:2380,docker-node2=http://172.16.247.132:2380 \
--initial-cluster-state new&
./etcdctl cluster-health
member 72400c6f5c5691f3 is healthy: got healthy result from http://172.16.247.131:2379
member dc0810ee9a06524d is healthy: got healthy result from http://172.16.247.132:2379
cluster is healthy

重啟docker服務

在docker-node1上執行:

sudo service docker stop
sudo /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://172.16.247.131:2379 --cluster-advertise=172.16.247.131:2375&

在docker-node2上執行:

sudo service docker stop
sudo /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://172.16.247.132:2379 --cluster-advertise=172.16.247.132:2375&

建立overlay network

在docker-node1上建立一個demo的overlay network

https://blog.csdn.net/qq_37880968/article/details/86747883

https://www.imooc.com/article/47152

https://blog.csdn.net/u013641234/article