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.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate