linux  mailserver

docker mailserver

Mailserver in einem Docker-Container...
Umstieg > mailcow: dockerized - 🐮 + 🐳 = 💕

Install

Docker - Install

sudo usermod -aG docker www-data
#reboot

sudo mkdir /var/www/mail
sudo chown -R www-data:www-data /var/www/mail
sudo chmod -R 775 /var/www/mail

cd /var/www/mail
DMS_GITHUB_URL="https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master"
wget "${DMS_GITHUB_URL}/compose.yaml"
wget "${DMS_GITHUB_URL}/mailserver.env"

docker compose create

Konfiguration

nano /var/www/mail/compose.yaml
nano /var/www/mail/mailserver.env

SSL

let's encrypt
#cert muss explizit im MX-Record-Ordner (yaml hostname:) liegen! 

UFW

sudo ufw allow 25
#sudo ufw allow 143
sudo ufw allow 465
sudo ufw allow 587
sudo ufw allow 993

Mail Konfiguration

#Mail Accounts anlegen
♯crypt♯

#Alias + Workaround CatchAll
#Als Workaround, wenn CatchAll genutzt werden soll, muss Reihenfolge beachtet werden und für explizite Accounts ein Alias angelegt werden.
sudo nano /var/www/mail/docker-data/heister.be/dms/config/postfix-virtual.cf
♯crypt♯

#Sieves aka Forwarding...
sudo nano /var/www/mail/docker-data/heister.be/dms/config/before.dovecot.sieve
♯crypt♯
#reboot?

/var/www/mail/docker-data/heister.be/dms/config/after.dovecot.sieve

/var/www/mail/docker-data/heister.be/dms/config/<user_login>.dovecot.sieve
#/var/www/mail/docker-data/heister.be/dms/config/user1@example.com.dovecot.sieve

Start/Stop

docker compose -f /var/www/mail/compose.yaml up -d
docker compose -f /var/www/mail/compose.yaml down

Autostart as Service...

Das scheint quatsch zu sein! Wenn der Container beim Reboot läuft, dann läuft er danach auch wieder. TADA 🥳

sudo tee /etc/systemd/system/mailserver.service >/dev/null <<'EOF'
[Unit]
Description=docker mailserver
After=syslog.target
After=network.target

[Service]
User=www-data
Restart=always
WorkingDirectory=/var/www/mail/
ExecStart=docker compose -f /var/www/mail/compose.yaml up
ExecStop=docker compose -f /var/www/mail/compose.yaml down
EOF

sudo chmod 755 /etc/systemd/system/mailserver.service

sudo systemctl enable mailserver.service
sudo systemctl start mailserver.service
sudo systemctl status mailserver.service
# sudo systemctl stop mailserver.service

Commands

docker exec -it mailserver setup help

docker exec -it mailserver setup email list
docker exec -it mailserver setup email update <EMAIL ADDRESS>

docker exec -it mailserver setup alias list
docker exec -it mailserver setup alias add <EMAIL ADDRESS> <RECIPIENT>

docker exec -it mailserver setup fail2ban
docker exec -it mailserver setup fail2ban status
docker exec -it mailserver setup fail2ban [<ban|unban> <IP>]

Linksammlung

Docker-Mailserver
First-Steps
Konfiguration
GitHub
Hetzner-DNS
Sieve-Editor