We all know that docker containers in the same host can access each other, so can docker containers in different hosts access each other?
The answer is yes, the solution is to add the network segment of the docker container on another host to the routing table in the host.
The existing host A is 192.168.124.51 and host B is 192.168.124.55. The specific steps are as follows:
1. Modify the network segment used by the docker container of one host (the default is 172.17.x.x)
2. Assume that the docker network segment has been modified. For example, the docker container in host A uses the 10.1.x.x network segment, and the docker in host B uses the 172.17.x.x network segment.
Add the routing table in A
sudo route add -net 172.17.0.0 netmask 255.255.0.0 gw 192.168.124.55
Add
sudo route add -net 10.1.0.0 netmask 255.255.0.0 gw 192.168.124.51
to host B. At this point, the containers in hosts A and B can access each other.
For more related tutorials, please pay attention to the docker tutorial column on the PHP Chinese website.
The above is the detailed content of How do two different docker hosts access each other?. For more information, please follow other related articles on the PHP Chinese website!