Interview Prep/Docker/Networking and Compose

Explain what Docker does with iptables when you publish a port.

AdvancedScenarioNetworking and Compose
Answer

Situation read → Interviewers probe whether you know why ufw doesn't block it.

What I'd do → Inspect:

iptables -t nat -L DOCKER -n
iptables -L DOCKER-USER -n

Docker adds a DNAT rule in the nat table for -p, a MASQUERADE for egress, and forwarding rules in filter. Place your restrictions in DOCKER-USER, which is evaluated first.

Why → Traffic is DNAT'd in PREROUTING and goes through FORWARD, never reaching the INPUT chain where ufw typically sits. Newer engines can use nftables (experimental in 29).

Interview tip → Bind published ports to specific IPs as the simplest control.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose