DEV Community

Cover image for Docker Tips - UFW
Rhuaridh
Rhuaridh

Posted on • Originally published at rhuaridh.co.uk

11 2

Docker Tips - UFW

Docker Tips - UFW

By default docker will override the "Uncomplicated Firewall" (UFW) rules, it is important to be aware of this so that you do not accidentally expose your docker containers to the world.

If you had UFW configured to block port 3000, then you would be forgiven for assuming our docker app would also be blocked.

docker run -d -p 3000:5000 training/webapp python app.py

However, docker adds rules to IP tables directly. This bypasses UFW which causes our app to be exposed to the world.

Two simple solutions

1) Bind port to localhost

The problem is that our port mapping tag exposes our app:

-p 3000:5000

Restricting access to localhost is a simple change:

-p 127.0.0.1:3000:5000

This binds port 5000 inside the container to port 3000 on the localhost or 127.0.0.1 interface on the host machine.

Our app is now blocked from external traffic!

2) Use external firewalls

GCP, AWS and even OVH all have external firewalls that sit infront of the server. Leveraging cloud based firewalls in addition to UFW is the best way to solve the issue.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more