不同宿主机上docker容器网络互通

时间:2021-06-11 09:35:36

Env

Server A: 172.18.27.65 docker0: 172.19.10.1

Server B: 172.18.27.66 docker0: 172.19.20.1

Operation

# In Server A

vim /etc/docker/daemon.json

{ "bip": "172.19.10.1/24" }

systemctl restart docker

ip route add 172.19.20.0/24 via 172.18.27.66

iptables -P INPUT ACCEPT

iptables -P FORWARD ACCEPT

iptables -F

iptables -L -n

 

# In Server B

vim /etc/docker/daemon.json

{ "bip": "172.19.20.1/24" }

systemctl restart docker

ip route add 172.19.10.0/24 via 172.18.27.65

iptables -P INPUT ACCEPT

iptables -P FORWARD ACCEPT

iptables -F

iptables -L -n