---
title: "Docker port reachable despite UFW"
category: "code"
id: 09b9973e-3f1d-46f5-a0e7-15fd6e7f7c1a
canonical: https://solvedlist.com/solutions/docker-port-reachable-despite-ufw
---

# Docker port reachable despite UFW

> Solution to block Docker container ports exposed to the internet while keeping UFW and iptables active, by adding rules to DOCKER-USER chain.

## Question

Docker container port is reachable from the internet despite UFW denying incoming and no port forwarding. How to block it without disabling iptables

## Solution

Symptom: `ufw status` is active with default deny incoming, yet a container started with `-p 8080:8080` answers from the internet.

Cause: Docker publishes ports by writing DNAT rules into the nat table and its own DOCKER chains into filter. Forwarded traffic is accepted there before UFW's rules ever see it.

Scope: this applies to Docker with the iptables backend, the default on most distributions. With the nftables backend there is no DOCKER-USER chain and the rule below matches nothing.

Fix, never set `"iptables": false`, that breaks container networking. Restrict forwarded traffic in DOCKER-USER, which Docker evaluates before its own rules. Add above the final COMMIT of the `*filter` block in `/etc/ufw/after.rules`:
```
:DOCKER-USER - [0:0]
-A DOCKER-USER -i eth0 -p tcp -m conntrack --ctorigdstport 8080 --ctdir ORIGINAL -j DROP
```
then `ufw reload` while Docker is running, and replace `eth0` with the external interface from `ip -br a`.

The rule covers IPv4 TCP only. A service published on `::` stays reachable over IPv6: add the same line via `ip6tables` to `/etc/ufw/after6.rules`, and use `-p udp` for UDP. Check both chains with `iptables -S DOCKER-USER` and `ip6tables -S DOCKER-USER`.

Verify from a host outside the network: `curl -m 5 http://<public-host>:8080` must time out, while containers on the same Docker network still reach the service.

## Query directly via MCP

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}
```

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
