Docker contanier comunication with route

时间:2023-03-10 04:39:29
Docker contanier comunication with route

2台宿主机,hslave1 192.168.1.153, hslave2 192.168.1.154

修改网段


docker0默认网段是172.17.0.0/16,修改154机器的docker0的网段

vi /usr/lib/systemd/system/docker.service

#修改下面这行

ExecStart=/usr/bin/docker daemon --bip=172.18.42.1/16 -H fd:// -H=unix:///var/run/docker.sock

重启Docker

systemctl stop docker

systemctl start docker

修改宿主机路由


153

route add -net 172.18.0.0/16 gw 192.168.1.154

154

route add -net 172.17.0.0/16 gw 192.168.1.153

这里添加的路由规则在宿主机重启后,会消失。

Docker contanier comunication with route

Docker contanier comunication with route

启动容器互联


154容器连接153MYSQL

Docker contanier comunication with route

153连接154MYSQL

Docker contanier comunication with route