I’m experimenting with Docker networking and have set up the following scenario:
- Networks:
s1
: User-defined Docker network 1s2
: User-defined Docker network 2
- Containers:
Container1
(connected tos1
)Container2
(connected to boths1
ands2
)Container3
(connected tos2
)
The containers are just:
docker run -d --name c1 --network s1 alpine tail -f /dev/null
I’m trying to ping C3 from C1 and vice-versa, making C2 the middle man to foward this packet since its in both networks. But I can’t get this working. I have tried setting “net.ipv4.ip_forward = 1” >> /etc/sysctl.conf and ran an entrypoint script with this iptables rules, without success:
iptables -I DOCKER-USER -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING --out-interface eth0 -j MASQUERADE
Any tips? Am I going in the wrong direction?