> ## Content Index
> Fetch the complete content index at: https://ping2prompt.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Docker published ports bypass ufw rules: check yours before the weekend
- URL: https://ping2prompt.com/docker-published-ports-bypass-ufw-rules-check-yours-before-the-weekend/
- Published: 2026-11-16T02:40:19.000Z
- Updated: 2026-11-16T22:52:35.000Z
- Description: Docker's docs say publishing a container port with -p or --publish diverts its traffic before ufw's settings apply, so the firewall is effectively ignored. Check which containers publish ports, drop unneeded ones, and test from a second machine.
- Author: Ping2Prompt Newsroom
- Tags: Docker, The Friday Footgun, #auto, #docs-reviewed, #short-ping

## The default

You have a host firewall set to deny incoming traffic, and a container with a published port. Docker's docs say that publishing a container's ports diverts its traffic before ufw's settings apply. ufw is a frontend for managing firewall rules, and it ships with Ubuntu. The docs describe Docker and ufw as incompatible in how they use firewall rules.

## Why it bites

On Linux, Docker creates its own firewall rules for network isolation, port publishing and filtering. It says bridge networks need those rules to work, and it tells you not to modify them. Docker routes container traffic in the nat table.

That means packets are diverted before they reach the INPUT and OUTPUT chains that ufw uses. The docs say the practical result is that your firewall configuration is effectively ignored for that traffic. The trigger is publishing: the -p or --publish flag makes a container port available outside the host.

Without publishing, a bridge-network port is reachable from the host and from containers on the same network. By default it is not reachable from outside the host. Docker creates these rules for bridge networks only, and not for ipvlan, macvlan or host networking.

Docker uses iptables by default, and nftables is also supported with the same functionality for bridge networks. Docker also turns on IP forwarding at startup if it is off, then sets the firewall to drop forwarded packets unless they are explicitly accepted.

The sources we reviewed do not mention the DOCKER-USER chain, and they do not describe rule ordering, so we will not claim more than the docs say. They also do not state which address a bare published port listens on, so check that on your own hosts.

## How to check

Here is what the documentation supports, and what it does not. Verify before running anything: search your docker run commands and compose files for the -p or --publish flag, because that flag is what opens a port beyond the host. Verify before running: open /etc/docker/daemon.json and look for the iptables or ip6tables keys set to false, which changes how Docker handles its rules.

Verify before running: check /etc/docker/daemon.json and your dockerd options for firewall-backend, which selects iptables or nftables. The sources do not document any command for listing listening sockets or inspecting Docker's chains, so we are not presenting one as documented. The most honest test is to try the port from a second machine on your network, not from the server itself.

## The fix

Start by publishing less. If a service only needs to be reached by other containers, leave out the publish flag, since bridge-network ports stay reachable from the host and from containers on the same network. The cost is that other machines can no longer reach that service directly.

For backends that need no outside access, Docker's docs say a container can connect to an --internal network. User-defined bridge networks let containers talk by IP address or by container name, while the default bridge allows only IP addresses. The cost there is that you now manage named networks yourself.

Do not try to quiet the conflict by switching Docker's firewall rules off. The docs say setting the iptables or ip6tables keys to false is not appropriate for most users and is likely to break container networking. With no replacement rules, containers lose masquerading to the internet, and all their ports become accessible to hosts on the local network.

The docs also say you cannot completely stop Docker from creating firewall rules, and that adding rules afterwards is extremely involved. The ip-forward-no-drop setting is not a ufw fix: it only stops Docker setting the forwarding policy to drop, and the docs recommend that policy unless the host must act as a router. Docker points to its port publishing documentation for details on disabling publishing and using direct routing.

The sources we reviewed do not cover binding a port to one address, publishing only through a reverse proxy, or filtering rules for published ports, so read that page before relying on any of them. This is configuration guidance; the sources list no CVE and no patched release.

## Friday checklist

List every container on your hosts that has a published port. Remove the ones nobody off-host needs. Test the rest from a second machine on your network. Leave Docker's own rules unedited, as its docs advise.

## Sources

- [docs.docker.com/engine/network/packet-filtering-firewalls](https://docs.docker.com/engine/network/packet-filtering-firewalls/?ref=ping2prompt.com)
- [docs.docker.com/engine/network](https://docs.docker.com/engine/network/?ref=ping2prompt.com#published-ports)

Image: [Photo by Jordan Harrison on Unsplash](https://unsplash.com/photos/blue-utp-cord-40XgDxBfYXM?utm%5Fsource=ping2prompt&utm%5Fmedium=referral)

---

This story was produced with AI assistance from the sources listed above and fact-checked against them before publication. Read our [editorial methodology](https://ping2prompt.com/about-how-we-work/) and the [corrections log](https://ping2prompt.com/corrections/). Spotted an error? Email [editor@ping2prompt.com](mailto:editor@ping2prompt.com).