How to Build a Rspamd Docker Image
Rspamd is a powerful and free spam filtering system. Unfortunately, there is no official Docker image available so let’s build one for ourselves.
If you only want rspamd to run in a container the Dockerfile is very simple: Just install the rspamd packages and set the command to /usr/sbin/rspamd -f
. But rspamd can also expose a minimal web interface with statistics, logs and the ability to manually submit ham and spam. Of course we want that, too.
We use nginx to serve the necessary style sheets and icons for the rspamd web interface. These are included in the rspamd package. To make things easier we run both rspamd and nginx in the same docker container. We start them both at the same time using supervisord, one of the methods recommended by the Docker docs.
So this is our Dockerfile: it installs the necessary packages, copies the supervisord config and nginx config and starts supervisord.
FROM alpine:3.17 |
We let nginx pick the static files from the rspamd package location and proxy the http requests to rspamd itself. Output goes to /dev/stdout
to populate the Docker logs.
worker_processes 2; |
We let rspamd also log to the console.
type = console |
Supervisord has the ability to start multiple processes but stay in foreground itself which is very convenient in docker containers as the main command stays alive. We use it to start rspamd and nginx, again, in foreground. Rspamd has a switch for that, nginx needs an additional option string.
[supervisord] |
Build your image like this:
docker build -t dovecot:2.3.19.1-r0-2 . |
And that’s it. Build your image from the recipe above or just take my prebuilt Rspamd Docker image.