1. Overview of Cross-Host Networking
Several network schemes of Docker have been learned before: none, host, bridge and joined containers, which solve the problem of container communication within a single Docker Host. The focus of this chapter is to discuss scenarios for communication between containers across hosts.
Docker native overlay and macvlan.
Third-party solutions: Commonly used ones include flannel, weave and calico.
2. Prepare the overlay environment
To support container communication across hosts, Docker provides an overlay driver. Docerk overlay network requires a key-value database to store network status information, including Network, Endpoint, IP, etc. Consul, Etcd and ZooKeeper are all key-vlaue software supported by Docker, we use Consul here.
1. Environment description
We will directly use the experimental environment created by docker-machine in the previous section. Practice various cross-host networking scenarios on docker hosts host1 (192.168.1.201) and host2 (192.168.1.203), and deploy supported components such as Consul on 192.168.1.200.
2. Create consul
Execute the following command on the device 192.168.1.200.
docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap
After the container starts, Consul can be accessed at http://192.168.1.200:8500 .
3. Modify the docker configuration file
Next, modify the configuration file /etc/systemd/system/docker.service.d/10-machine.conf of the docker daemon of host1 and host2.
--cluster-store Specifies the address of consul.
--cluster-advertise Tell consul its own connection address.
Restart the docker daemon.
systemctl daemon-reload
systemctl restart docker.service
host1 and host2 will be automatically registered with the Consul database.
4. Ready
Ready, the experimental environment is as follows: