Symptom: UFWUFW Uncomplicated Firewall. A friendly front end to the Linux firewall (iptables or nftables) on Ubuntu and Debian. is set to deny incoming by default. ufw status looks perfect. And yet a containercontainer A lightweight, isolated package of an application and its dependencies. It shares the host's kernel, so it starts in seconds, unlike a full virtual machine.’s port is reachable from another machine.
Cause: when you publish a port with -p 8080:80 or ports: in Compose, DockerDocker A tool for packaging software and everything it needs into containers, so it runs the same way on any machine. writes its own iptablesiptables The classic Linux packet-filtering rules engine. Docker writes its own rules here, which is how published ports can bypass UFW. rules to forward traffic to the container. Those rules are evaluated before UFW’s, so UFW never gets a vote. It isn’t a bug so much as two tools that each assume they own the firewall.
Fixes, from simplest:
- Don’t publish what doesn’t need publishing. Containers on the same Docker network can talk to each other without any published ports.
- Bind to localhost when only the host needs it:
127.0.0.1:8080:80. - Use the
DOCKER-USERchain for rules Docker won’t overwrite, if something truly has to be exposed. - Put a tunnel or reverse proxyreverse proxy A server that sits in front of your applications and receives requests on their behalf, handling TLS, routing and access checks in one place. in front and publish nothing at all. This site works that way.
Check it yourself: from a different machine, not the host.
docker ps --format '{{.Names}}\t{{.Ports}}'
sudo iptables -L DOCKER -n --line-numbers
nmap -Pn -p- <your-own-host> # only against machines you own
Lesson: a firewall’s status output tells you what it intends. Only a test from the outside tells you what’s true.
Applies to: Docker Engine on Linux hosts that use UFW, with Docker managing iptables (its default). Checked October 2026.



