# Docker published ports can get past UFW

> A published container port listens on every interface, and Docker's own iptables rules handle it before UFW's do. Bind to 127.0.0.1 when a proxy sits in front.

- Author: Braveen Nagendram
- Published: 2026-11-29
- Tags: docker, networking, security
- Canonical: https://www.braveen.me/til/docker-published-ports-bypass-ufw/

During a security review I found an API that was meant to sit behind a reverse proxy, answering directly from outside on port 8000. UFW was enabled, and port 8000 wasn't allowed. The Compose file had this:

```yaml
ports:
  - "8000:8000"
```

Two things combine here.

**A published port binds to every interface by default.** `"8000:8000"` is short for `"0.0.0.0:8000:8000"` (and the IPv6 equivalent), so the host listens on all its addresses, the public one included. That doesn't automatically mean the whole internet can reach it. A cloud provider's firewall or a home router in front of the machine can still block it. But nothing on the host itself will.

**Docker's rules come before UFW's.** To publish a port, Docker adds a DNAT rule in the `nat` table that rewrites traffic for port 8000 to the container's address. That traffic is then *forwarded* to the container, so it passes through the `FORWARD` chain, where Docker has its own `DOCKER` chains. It never reaches `INPUT`, which is where UFW's rules for the host live. UFW is doing exactly what it was told, just for traffic that this traffic never goes through.

If a service is only meant to be reached through a proxy on the same host, bind it to loopback:

```yaml
ports:
  - "127.0.0.1:8000:8000"
```

If it really does need to be reachable but filtered, Docker gives you the `DOCKER-USER` chain for your own rules, which it evaluates before its own.

Either way, check from another machine rather than trusting the firewall config:

```sh
nmap -p 8000 your-server
```

This came up during the same review as [the backdoor I missed for 131 days](/blog/the-backdoor-i-missed-for-131-days/).
