Docker communication between multiple machines.

How do containers on different machines communicate? (VXLAN can see the details on the official website.)

 

 

 

First, the two hosts can communicate.

Docker's overlay network. (Bridge host none is a single machine. Overlay is a multi-machine network)

The two northernmost hosts with docker installed are docker1 and docker2!

Then you need a tool for distributed storage. (This is to ensure that the ip address is not duplicated. For example, on the docker1 host, the ip of one of the containers is 172.17.0.2. Then you need to ensure that the ip address of another container on the other machine can also be 172.17.0.2. Yes It is 172.17.0.3 172.17.0.4. So a distributed storage tool is needed to ensure these.)

Use etcd here

# Both hosts are installed:

[miller @ docker4 download] $ ls 
Python - 3.7 . 7   Python- 3.7 . 7 .tgz v3. 4.7 
[miller @ docker4 download] $ rm v3. 4.7  
[miller @ docker4 download] $ wget https: // github.com/ IO-ETCD / ETCD / Releases / downloads / v3.4.7 / ETCD-v3.4.7-Linux-amd64.tar.gz 
- 2020 - 04 - . 11  18 is : 47 : 37 [ - HTTPS: // github.com/etcd -io / etcd / releases / download / v3.4.7 / etcd-v3.4.7-linux-amd64.tar.gz 
is resolving the host github.com (github.com) ... 52.74 . 223.119
Connecting to github.com (github.com) | 52.74 . 223.119 |: 443 ... connected. 
An HTTP request has been sent and is waiting for a response ... 302 Found 
location: https: // github-production-release-asset-2e65be.s3.amazonaws.com/11225014/cd901e00-7419-11ea-88fc-732f4a7bec4f?X-Amz -Algorithm = AWS4-HMAC-SHA256 & X-Amz-Credential = AKIAIWNJYAX4CSVEH53A% 2F20200411% 2Fus-east-1% 2Fs3% 2Faws4_request & X-Amz-Date = 20200411T104738Z & X-Amz-Expires = 300 & X-Amz-Signature = 879d4434d3aa1db5bcb75cf57c3d139c5ae98904941d1aa3a41ad656774a9766 & X-Amz-SignedHeaders = host & actor_id = 0 & repo_id = 11225014 & response-content-disposition = attachment% 3B% 20filename% 3Detcd-v3.4.7-linux-amd64.tar.gz &- 04 - . 11  18 is : 47 : 38 is - HTTPS: // github-production-release-asset-2e65be.s3.amazonaws.com/11225014/cd901e00-7419-11ea-88fc-732f4a7bec4f?X-Amz-Algorithm=AWS4 -HMAC-SHA256 & X-Amz- Credential = AKIAIWNJYAX4CSVEH53A% 2F20200411% 2Fus-east-1% 2Fs3% 2Faws4_request & X-Amz-Date = 20200411T104738Z & X-Amz-Expires = 300 & X-Amz-Signature = 879d4434d3aa1db5bcb75cf57c3d139c5ae98904941d1aa3a41ad656774a9766 & X-Amz-SignedHeaders = host & actor_id = 0 & repo_id = 11225014 & response -content-disposition = attachment% 3B% 20filename% 3Detcd-v3.4.7-linux-amd64.tar.gz & response-content-type = application% 2Foctet-stream 
is resolving the host github-production-release-asset-2e65be.s3.amazonaws .com (github-production-release-asset-2e65be.s3.amazonaws.com) ...52.216 . 133.75 
Connecting GitHub -production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com) | 52.216 . 133.75 |: 443 ... connected. 
HTTP request has been sent, waiting for response ... 200 OK 
Length: 17310840 (17M) [application / octet- stream] 
is being saved to: "etcd -v3. 4.7 -linux- amd64.tar.gz" 

100 % [== ================================================== ================================================== =======================>] 17 , 310 , 840   3 .38MB / s time 5.1s    

2020 - 04 - . 11  18 is : 47 : 45 ( 3.26 MB / S) - Saved "ETCD-V3. 4.7 -linux-amd64.tar.gz" [ 17.31084 million / 17.31084 million ])

[miller@docker4 download]$ tar -zxvf etcd-v3.4.7-linux-amd64.tar.gz

[miller@docker4 download]$ cd etcd-v3.4.7-linux-amd64/

Then configure separately

[miller@docker4 etcd-v3.4.7-linux-amd64]$ nohup ./etcd --name 'docker4' \
> --initial-advertise-peer-urls 'http://192.168.42.22:2380' \
> --listen-peer-urls 'http://192.168.42.22:2380' \
> --listen-client-urls 'http://192.168.42.22:2379' \
> --advertise-client-urls 'http://192.168.42.22:2379' \
> --initial-cluster-token 'etcd-cluster' \
> --initial-cluster 'docker4 = http: //192.168.42.22: 2380, docker5 = http: //192.168.42.23: 2380 ' \
 > --initial-cluster-state ' new & '  
nohup: ignore the input and append the output to " nohup.out "

 


[miller@docker4 etcd
-v3.4.7-linux-amd64]$ nohup ./etcd --name 'docker5' \ > --initial-advertise-peer-urls 'http://192.168.42.23:2380' \ > --listen-peer-urls 'http://192.168.42.23:2380' \ > --listen-client-urls 'http://192.168.42.23:2379, http://127.0.0.1:2379' \ > --advertise-client-urls 'http://192.168.43.23:2379' \ > --initial-cluster-token 'etcd-cluster' \ > --initial-cluster 'docker4 = http: //192.168.42.22: 2380, docker5 = http: //192.168.42.23: 2380 ' \ > --initial-cluster-state ' new & ' nohup: ignore the input and append the output to " nohup.out "

 

Listen to the docker that will start this. Because let docker know that we used etcd.

 

Karma ordered

 

Guess you like

Origin www.cnblogs.com/chengege/p/12682172.html