I am using docker to run containers.
I don't want the containers to have access to the other containers but I want them to still have access to external communication like using apt update
.
The containers network is 172.17.0.0/16
, if I just block like that:
iptables -I FORWARD -i docker0 -d 172.17.0.0/16 -j DROP
It works but then they can't use apt update
, it can't find from where to download because it probably goes out from the gateway.
Therefore I wanted to allow connection to the gateway (172.17.0.1
) so I tried to allow it like that:
iptables -A INPUT -i docker0 -d 172.17.0.1/32 -j ACCEPT
iptables -A OUTPUT -o docker0 -d 172.17.0.1/32 -j ACCEPT
But the problem still exist, it can't use apt update
:
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
Temporary failure resolving 'archive.ubuntu.com'
Only when I remove the block rule it works again:
iptables -I FORWARD -i docker0 -d 172.17.0.0/16 -j DROP