← Back to Blog Tech

The Docker Firewall Loophole: Exposed Ports Bypass Your Server Firewall

If you run anything in Docker, you probably assume your server's firewall protects your ports. It doesn't.

While deploying, I noticed something worrying. I had blocked external traffic to a custom backend port, yet I could still reach it unencrypted from the public internet. The reason: Docker injects its bridge rules directly into the Linux kernel, ahead of your OS firewall. If you expose a port, it's open to the world.

My first attempt was to fix it in the OS by rewriting our nftables.conf tables. It held for an hour, then a routine system reload wiped out Docker's mappings, produced DNAT rule mapping errors, and took our webmail offline.

The actual fix: Instead of fighting Docker inside the OS, I moved the firewall off the server. Using our provider's (Contabo) cloud-level firewall, incoming packets are blocked before they ever reach the VM's network card. The Docker loophole is closed, the container setup stays standard, and the box sits behind an external wall we control.