Ubuntu - Dockerising/moving mailman2 lists with static, public IP

Items that you should almost certainly change are in bold.

Setting up Docker

snap install docker
docker  pull d3fk/mailman2:stable
mkdir /var/log/apache2

Preparation

First, copy your /var/lib/lists tree to somewhere convenient which you can use as a volume for mailman's docker container.

Email

You need to create a file in /etc/exim4/conf.d/main/00_local_macros_override with the contents

    MAIN_RELAY_NETS = 127.0.0.1 : ::::1 : 192.168.0.0/16 : 172.16.0.0/12
This will ensure that you do not get "relay prohibited" errors from outgoing mails.

Running the container

The following script worked for me, setting up a static public IP address

! /bin/bash

IP=1.2.3.4	# Your chosen IP address
dev=enp0s25	# Your interface name
hostname=docker.mydomain.org

# Stop any existing mailman container
if docker ps -a | grep -q mailman ; then
    docker stop mailman
fi

# Do we need to add our IP range to the ethernet interface?
if  ip addr list | grep -q $IP ; then
    true ;
else
    ip addr add ${IP}/29 dev $dev
fi

docker volume create apachelogs
docker run --rm -d --name mailman \
             --add-host ${hostname}:$IP \
             --hostname ${hostname} \
             -p ${IP}:80:80 -p ${IP}:443:443 -p ${IP}:25:25 -p ${IP}:465:465 -p ${IP}:587:587 \
             -e URL_HOST=docker.mydomain.org \
             -e EMAIL_HOST=${hostname} \
             -e LIST_ADMIN=list_admin_user@mydomain.org \
             -e MASTER_PASSWORD="seekrit" \
             -e URL_PATTERN="http" \
             -e SSL_FROM_CONTAINER="true" \
             -e SSL_SELFSIGNED="true" \
             -v apachelogs:/var/log/apache2 \
             -v $(pwd)/lists:/var/lib/mailman/lists \
             -v $(pwd)/dkimcert:/etc/exim4/tls.d \
             d3fk/mailman2

Fixups

You may need to change the hostname in your list configuration. To do this:

docker exec -it mailman bash
cd /var/lib/mailman
# Repeat for each list ...
bin/withlist  -l -r fix_url my_list -u docker.mydomain.org
exit