Docker practice across the host network

Docker use network management is the most troublesome, during its initial early on the need for proper planning, if the network communication ideal single-host is relatively simple, but if it comes to cross-host of the network you need to use docker comes the overlay network or a third-party network plug-ins, this is a direct way to achieve the use of native plug-in host access across the container.

Basic conditions
1.docker version needs 1.9
2.Linux kernel version 3.19 or more (centos kernel practice is 3.10, does not appear abnormal, the latter need to verify)
can correctly communicate across hosts 3

consul service to build
Docker host communication needs across key value services to save information network, there are many services that can be selected, as consul, etcd, zookeeper and so can, this is the official recommended consul service as a key value of service.

docker run -d --restart="always" --publish="8500:8500" --hostname="consul" --name="consul" index.alauda.cn/sequenceiq/consul:v0.5.0-v6 -server -bootstrap

 Foreign mirrored pull very slowly, the choice of the domestic spirit bird cloud as a service.

Configuration transformation
as it has been used docker1.19 version in centos system's / etc / sysconfig / docker no longer exists, but needs new in the /etc/systemd/system/multi-user.target.wants/docker.service by two configuration items
1 .-- cluster-store = consul: //10.19.137.180: IP address # 8500 in the network plus the port consul, available to join the service to address cross-network communication
2 .-- cluster- advertise = eth0: 2375 # started in daemon mode
the same information and fill out the card itself communication service address consul in another one of the server, the server needs to re-load the configuration and restart the docker container after editing.

systemctl daemon-reload
systemctl restart docker

Create overlay network
using the network command to create overlay categories

docker network create -d overlay leo

After using docker network ls command you will find two servers have leo this network, indicating all the best

Test Network
were created docker container tested two servers
Server 1

docker run -itd --name=leo_zhou1 --net=leo  busybox

Server 2

docker run -itd --name=leo_zhou2 --net=leo  busybox

Enter leo_zhou1 test whether the ping leo_zhou2

Guess you like

Origin www.cnblogs.com/zhouzhifei/p/11987355.html