Docker publishes a port and bypasses your ufw rules. Why?
IntermediateScenarioSecurity: Firewalls, SGs, NACLs & VPN
Answer
Situation read → Docker inserts its own iptables rules ahead of ufw's chains.
What I'd do →
- Understand that
-p 8080:80creates DNAT in the nat table and ACCEPT inDOCKERchain, used before ufw's INPUT rules - Check with
iptables -L DOCKER-USER -n - Add restrictions in the
DOCKER-USERchain:iptables -I DOCKER-USER -i eth0 ! -s 203.0.113.0/24 -j DROP - Or bind to localhost:
-p 127.0.0.1:8080:80 - Use cloud security groups as the real boundary
Why → Published container ports are forwarded traffic, which doesn't pass through INPUT.
Interview tip → Say you never rely on host firewalls alone for containers.
More on Security: Firewalls, SGs, NACLs & VPN
Security group versus NACL: explain the differences.BeginnerHow do you let only your office IP SSH into a server?BeginnerWhat does it mean that a security group can reference another security group?BeginnerStateful versus stateless firewalls: what is the practical difference?BeginnerWhat is a WAF and where do you place it?BeginnerWhat is the difference between a site-to-site VPN and a client VPN?Beginner