overlay cross-network interconnection
Trial planning
- Configure the consul environment
docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap
After the container starts, you can access consul through http://192.168.195.131:8500
- Modify host1, host2 configuration
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --cluster-store=consul://192.168.195.131:8500 --cluster-advertise=ens33:2376
Modify the docker.service files of host1 and host2 (the location of docker.service of different versions of docker may be different), and execute:systemctl daemon-reload systemctl restart docker.service
Visit 192.168.195.131:8500/ui/#/dc1/kv/docker/nodes/ to view the two host information
- Create overlay network
docker network create -d overlay ovnet
This command can be executed on either host1 or host2, the other one will be automatically synchronized
- View overlay network
docker network ls
The scope of ovnet is global
docker network inspect ov_net
subnet:10.0.0.0/24;gateway:10.0.0.1
- test interconnect
docker run -t --network ovnet --name c1 centos
docker run -t --network ovnet --name c2 centos
Run c1 on host1 and c2 on host2 (names cannot be the same)
docker exec c1 ping -c 3 c2