In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how docker implements container communication on different Linux machines". The content of the article is simple and clear, and it is easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "how docker implements container communication on different Linux machines".
There are many tools for distributed storage. Today we choose the etcd tool, which is open source free distributed storage.
Prepare the lab environment:
Docker node1 ip: 192.168.0.109
Docker node2 ip: 192.168.0.107
On docker node1, download and extract the https://github.com/etcd-io/etcd/releases/tag/v3.3.13
Vincent@swarm-manager:~/etcd-v3.3.13-linux-amd64 $nohup. / etcd--name docker-node1-initial-advertise-peer-urls http://192.168.0.109:2380\ >-listen-peer-urls http://192.168.0.109:2380\ >-listen-client-urls http://192.168.0.109:2379, Http://127.0.0.1:2379\ >-- advertise-client-urls http://192.168.0.109:2379\ >-- initial-cluster-token etcd-cluster\ >-- initial-cluster docker-node1= http://192.168.0.109:2380,docker-node2=http://192.168.0.107:2380\ >-- initial-cluster-state new & [1] 3870vincent@swarm-manager:~/etcd-v3.3.13-linux-amd64 $nohup: ignoring input and appending output to 'nohup.out'
-- name means the name is docker-node1
-- initial-advertise-peer-urls indicates the local address
. / etcdctl cluster-healthmember 72400c6f5c5691f3 is healthy: got healthy result from http://172.16.247.131:2379member dc0810ee9a06524d is healthy: got healthy result from http://172.16.247.132:2379cluster is healthy
Also execute on docker node2:
Wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gzvincent@swarm-worker-1:~/etcd-v3.3.13-linux-amd64$. / etcd-name docker-node2-- initial-advertise-peer-urls http://192.168.0.107:2380\ >-- listen-peer-urls http://192.168.0.107:2380\ >-- listen-client-urls Http://192.168.0.107:2379, Http://127.0.0.1:2379\ >-advertise-client-urls http://192.168.0.107:2379\ >-initial-cluster-token etcd-cluster\ >-initial-cluster docker-node1= http://192.168.0.109:2380,docker-node2=http://192.168.0.107:2380\ >-initial-cluster-state new &
How to make sure that our cluster has been successfully established:
Execute on node1:
Vincent@swarm-manager:~/etcd-v3.3.13-linux-amd64 $. / etcdctl cluster-healthmember beb7fd3596aa26eb is healthy: got healthy result from http://192.168.0.109:2379member e6bdc10e37172e00 is healthy: got healthy result from http://192.168.0.107:2379cluster is healthy
Then execute on node2:
Vincent@swarm-worker-1:~/etcd-v3.3.13-linux-amd64 $. / etcdctl cluster-healthmember beb7fd3596aa26eb is healthy: got healthy result from http://192.168.0.109:2379member e6bdc10e37172e00 is healthy: got healthy result from http://192.168.0.107:2379cluster is healthy
So we built a distributed storage on two machines.
Restart the docker service
Because we want to let docker know that we are going to use distributed storage.
Execute on docker-node1:
Vincent@swarm-manager:~/etcd-v3.3.13-linux-amd64 $sudo service docker stop [sudo] password for vincent:vincent@swarm-manager:~/etcd-v3.3.13-linux-amd64 $docker-- versionDocker version 17.12.0-ce, build c97c6d6
Then start docker manually:
Vincent@swarm-manager:~/etcd-v3.3.13-linux-amd64 $sudo / usr/bin/dockerd-H tcp://0.0.0.0:2375-H unix:///var/run/docker.sock-- cluster-store=etcd://192.168.0.109:2379-- cluster-advertise=192.168.0.109:2375& [2] 4153
Execute on docker-node2:
Sudo service docker stopsudo / usr/bin/dockerd-H tcp://0.0.0.0:2375-H unix:///var/run/docker.sock-- cluster-store=etcd://192.168.0.109:2379-- cluster-advertise=192.168.0.109:2375& create overlay network
Create a demo overlay network on docker-node1
Sudo docker network lsNETWORK ID NAME DRIVER SCOPEf6acf1d69b7c bridge bridge localc051f46f8a15 host host local4caf51fb3438 none null localdocker network create-d overlay demo1607f5636b8515d7e06d2f13261d32d8370c72de99ffb688ccdce3f6d8bce898docker network lsNETWORK ID NAME DRIVER SCOPEf6acf1d69b7c bridge Bridge local1607f5636b85 demo overlay globalc051f46f8a15 host host local4caf51fb3438 none null local
View the details of the overlay network:
Docker network inspect demo [{"Name": "demo", "Id": "1607f5636b8515d7e06d2f13261d32d8370c72de99ffb688ccdce3f6d8bce898", "Created": "2019-07-01T07:52:43.137469208-07:00", "Scope": "global", "Driver": "overlay", "EnableIPv6": false, "IPAM": {"Driver": "default" "Options": {}, "Config": [{"Subnet": "10.0.0.0 false 24", "Gateway": "10.0.0.1"}]}, "Internal": false, "Attachable": false "Ingress": false, "ConfigFrom": {"Network": "}," ConfigOnly ": false," Containers ": {}," Options ": {}," Labels ": {}}]
We will see that on node2, the overlay network of this demo is created synchronously:
Docker network lsNETWORK ID NAME DRIVER SCOPEe944ecd3d81f bridge bridge local1607f5636b85 demo overlay globalca2b5e91ee2f host host localcfb09007c0ce none null local creates containers that connect to the demo network
Create a container on docker-node1:
Docker run-d-name test1-network demo vincent/ubuntu-base / bin/bash-c "while true; do sleep 3600; done" c86061fd856cca0d157cc602cd9b98edd9f0fa4db9a26aa77ae2b054d6d804f1docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc86061fd856c vincent/ubuntu-base "/ bin/bash-c 'while …" About a minute ago Up About a minute
Check the ip of test1:
Docker exec test1 ifconfigeth0 Link encap:Ethernet HWaddr 02:42:0a:00:00:02 inet addr:10.0.0.2 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0B) TX bytes:0 (0.0B) eth2 Link encap:Ethernet HWaddr 02:42:ac:12:00:02 inet addr:172.18.0.2 Bcast:172.18.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped 0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1308 (1.3 KB) TX bytes:0 (0.0B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped : 0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0B) TX bytes:0 (0.0B)
Create a new container test2 on docker-node2:
Docker run-d-name test2-network demo vincent/ubuntu-base / bin/bash-c "while true; do sleep 3600; done" 31f87913be02db7a8033b407c559a7a213445384d735239ff6504318c5077e46
Test connectivity on docker-node2
Docker exec-it test2 ifconfigeth0 Link encap:Ethernet HWaddr 02:42:0a:00:00:03 inet addr:10.0.0.3 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0B) TX bytes:0 (0.0B) eth2 Link encap:Ethernet HWaddr 02:42:ac:12:00:02 inet addr:172.18.0.2 Bcast:172.18.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors: 0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1308 (1.3 KB) TX bytes:0 (0.0B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors: 0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0B) TX bytes:0 (0.0B)
The two container can be connected.
Thank you for reading, the above is the content of "how docker implements container communication on different Linux machines". After the study of this article, I believe you have a deeper understanding of how docker implements container communication on different Linux machines, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.