A Docker container that provides network filtering capabilities for other containers, allowing you to restrict outbound network access to specific IPs, CIDR ranges, hostnames, and ports with protocol-specific rules. Code is largely AI generated (claude 3.7 Sonnet).
This container acts as a network filter, enforcing strict firewall rules on outgoing connections. It's designed to be used with Docker's network_mode: service:filter to apply these rules to other containers.
The container is configured through environment variables:
ALLOWED_IPS: Comma-separated list of allowed destinations
10.10.10.252,192.168.1.0/24,api.github.com,database.internalALLOWED_PROTOCOLS: Comma-separated list of allowed protocols
tcp,udp,icmptcp,udp (to block ICMP)ALLOWED_TCP_PORTS: Comma-separated list of allowed TCP ports
80,443,8080ALLOWED_UDP_PORTS: Comma-separated list of allowed UDP ports
53,123services:
filter:
image: aevrin/filter:latest
container_name: Filter-Compose
hostname: filter-compose
cap_add:
- NET_ADMIN
environment:
- ALLOWED_IPS=10.10.10.252,192.168.1.0/24,api.github.com
- ALLOWED_PROTOCOLS=tcp,udp,icmp
- ALLOWED_TCP_PORTS=80,443
- ALLOWED_UDP_PORTS=53,123
restart: unless-stopped
webserver:
image: aevrin/easy:latest
container_name: Webserver-Compose
network_mode: service:filter
depends_on:
filter:
condition: service_healthy
restart: unless-stopped
Allow access only to specific web services:
environment:
- ALLOWED_IPS=api.example.com,cdn.example.com
- ALLOWED_PROTOCOLS=tcp
- ALLOWED_TCP_PORTS=443
Allow access to a database subnet:
environment:
- ALLOWED_IPS=10.0.1.0/24
- ALLOWED_PROTOCOLS=tcp
- ALLOWED_TCP_PORTS=5432,3306
Combine different target types and protocols:
environment:
- ALLOWED_IPS=8.8.8.8,192.168.1.0/24,api.github.com,db.internal
- ALLOWED_PROTOCOLS=tcp,udp,icmp
- ALLOWED_TCP_PORTS=80,443,22
- ALLOWED_UDP_PORTS=53
The filter container sets up iptables rules to:
DNS Resolution:
Other containers use network_mode: service:filter to share the network namespace with the filter container, inheriting its firewall rules.
NET_ADMIN capability to manage iptables rulesThis container provides a security layer by restricting outbound network access, which can help:
Check the container logs to see configuration and dropped packets:
docker logs Filter-Compose
Look for log entries with prefixes:
OUTPUT-DROPPED: - Packets dropped from the container itselfFORWARD-DROPPED: - Packets dropped from containers using the filter's networkView current iptables rules:
docker exec Filter-Compose iptables -L -n -v
docker exec Filter-Compose ip6tables -L -n -v
You can allow different ports for different protocols:
environment:
- ALLOWED_IPS=example.com
- ALLOWED_PROTOCOLS=tcp,udp
- ALLOWED_TCP_PORTS=443 # HTTPS only
- ALLOWED_UDP_PORTS=53 # DNS only
Use CIDR notation for subnet access:
environment:
- ALLOWED_IPS=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 # Private networks
Combine IPs, CIDRs, and hostnames:
environment:
- ALLOWED_IPS=8.8.8.8,10.0.1.0/24,api.internal,github.com
Content type
Image
Digest
sha256:605d61562…
Size
13 MB
Last updated
2 days ago
docker pull aevrin/filter