How to scan Docker containers and local Kubernetes ports
When running Docker Compose or local Kubernetes clusters, publishing a port with -p 5432:5432 binds it to 0.0.0.0, exposing databases directly to the network and bypassing UFW firewall rules on Linux. Auditing these bindings takes only seconds.
cargo install open-port-scanner • Standalone CLI & GUIWhy Docker bypasses standard host firewalls
On Linux servers, Docker inserts its own DOCKER chain into iptables before the UFW or INPUT rules. As a result, a Redis or PostgreSQL container started with standard port mapping becomes reachable from the external network even if your host firewall blocks that port.
Auditing exposed container ports
To verify whether your containers are only bound to 127.0.0.1 or exposed across your LAN/public IP, scan your machine's network IP from another host or run a local sweep:
# Scan localhost for common web & dev server ports (3000, 5173, 8080, 9000):
port-scanner 127.0.0.1 --profile web
# Scan your server's LAN IP for exposed databases:
port-scanner 192.168.1.50 --profile database
# Scan full Kubernetes NodePort range (30000-32767) and export JSON:
port-scanner 10.0.0.10 -p 30000-32767 --json -o k8s-nodeports.json
Securing Docker Compose port bindings
If your scan detects an open database or admin port on your LAN/WAN IP that should remain private, bind it explicitly to localhost in docker-compose.yml:
# Unsafe (binds to 0.0.0.0):
ports:
- "5432:5432"
# Safe (accessible only from localhost):
ports:
- "127.0.0.1:5432:5432"