Fail2ban Docker image based on Alpine Linux
100K+
fail2ban (version 0.11) based on Alpine Linux
See my repository for more information and sources.
This image is a fork from crazymax
TZ : The timezone assigned to the container (default UTC)F2B_LOG_LEVEL : Log level output (default INFO)F2B_DB_PURGE_AGE : Age at which bans should be purged from the database (default 1d)F2B_MAX_RETRY : Number of failures before a host get banned (default 5)F2B_DEST_EMAIL : Destination email address used solely for the interpolations in configuration files (default root@localhost)F2B_SENDER : Sender email address used solely for some actions (default root@$(hostname -f))F2B_ACTION : Default action on ban (default %(action_)s)F2B_IPTABLES_CHAIN : Specifies the iptables chain to which the Fail2Ban rules should be added (default DOCKER-USER)SSMTP_HOST : SMTP server hostSSMTP_PORT : SMTP server port (default 25)SSMTP_HOSTNAME : Full hostname (default $(hostname -f))SSMTP_USER : SMTP usernameSSMTP_PASSWORD : SMTP passwordSSMTP_TLS : SSL/TLS (default NO):warning: If you want email to be sent after a ban, you have to configure SSMTP env vars and set F2B_ACTION to
%(action_mw)sor%(action_mwl)s
/data : Contains customs jails, actions and filters and Fail2ban persistent databaseDocker compose is the recommended way to run this image.
#Docker-compose file for fail2ban
version: "3.7"
services:
fail2ban:
image: darathor/fail2ban:latest
container_name: fail2ban
network_mode: "host"
cap_add:
- NET_ADMIN
- NET_RAW
volumes:
- "./data:/data"
- "/var/log:/var/log:ro"
restart: always
#environment:
#insert all variables below
You can also use the following minimal command :
docker run -d --name fail2ban --restart always \
--network host \
--cap-add NET_ADMIN \
--cap-add NET_RAW \
-v $(pwd)/data:/data \
-v /var/log:/var/log:ro \
darathor/fail2ban:latest
DOCKER-USER chainIn Docker 17.06 and higher through docker/libnetwork#1675, you can add rules to a new table called DOCKER-USER, and these rules will be loaded before any rules Docker creates automatically. This is useful to make iptables rules created by Fail2Ban persistent.
If you have an older version of Docker, you may just change F2B_IPTABLES_CHAIN to FORWARD. This way, all Fail2Ban rules come before any Docker rules but these rules will now apply to ALL forwarded traffic.
More info : https://docs.docker.com/network/iptables/
DOCKER-USER and INPUT chainsIf your Fail2Ban container is attached to DOCKER-USER chain instead of INPUT, the rules will be applied only to containers. This means that any packets coming into the INPUT chain will bypass these rules that now reside under the FORWARD chain.
This implies that sshd jail for example will not work as intended. You can create another Fail2Ban container. Take a look at this example.
Fail2ban commands can be used through the container. Here is an example if you want to ban an IP manually :
docker exec -t <CONTAINER> fail2ban-client set <JAIL> banip <IP>
Custom actions and filters can be added in /data/action.d and /data/filter.d. If you add an action/filter that already exists, it will be overriden.
:warning: Container has to be restarted to propagate changes
Jail examples can be found in examples/jails to work with this image.
Content type
Image
Digest
Size
35.3 MB
Last updated
over 7 years ago
docker pull darathor/fail2ban