From 24cf567d9a6865b4838035723da3fee66a3c5595 Mon Sep 17 00:00:00 2001 From: ayo Date: Fri, 12 Jun 2026 10:06:53 +0200 Subject: [PATCH] Initial: stack mail Postfix + Dovecot sur Alpine --- .gitignore | 2 ++ dovecot/Dockerfile | 22 ++++++++++++++++++++++ dovecot/dovecot.conf | 29 +++++++++++++++++++++++++++++ dovecot/users | 2 ++ postfix/Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 dovecot/Dockerfile create mode 100644 dovecot/dovecot.conf create mode 100644 dovecot/users create mode 100644 postfix/Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d21963 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vmail/ +*.log diff --git a/dovecot/Dockerfile b/dovecot/Dockerfile new file mode 100644 index 0000000..9a3c7e6 --- /dev/null +++ b/dovecot/Dockerfile @@ -0,0 +1,22 @@ +# Image de base Alpine +FROM alpine:3.21 + +# Installer Dovecot (IMAP/POP3) + le module d'authentification +RUN apk add --no-cache dovecot + +# --- Utilisateur vmail identique à celui de Postfix (uid/gid 5000) --- +RUN (deluser vmail 2>/dev/null || true) \ + && (delgroup vmail 2>/dev/null || true) \ + && addgroup -g 5000 vmail \ + && adduser -D -u 5000 -G vmail -h /var/mail/vhosts vmail \ + && mkdir -p /var/mail/vhosts + +# --- Copier nos fichiers de config dans l'image --- +COPY dovecot.conf /etc/dovecot/dovecot.conf +COPY users /etc/dovecot/users + +# Exposer les ports IMAP +EXPOSE 143 993 + +# Lancer Dovecot au premier plan +CMD ["dovecot", "-F"] diff --git a/dovecot/dovecot.conf b/dovecot/dovecot.conf new file mode 100644 index 0000000..146000a --- /dev/null +++ b/dovecot/dovecot.conf @@ -0,0 +1,29 @@ +# Protocoles servis +protocols = imap + +# Écouter sur toutes les interfaces +listen = * + +# --- Emplacement des boîtes : le même Maildir que Postfix --- +mail_location = maildir:/var/mail/vhosts/%d/%n +# %d = domaine (ayoinc.test), %n = partie locale (alice, bob) + +# --- Authentification --- +disable_plaintext_auth = no +auth_mechanisms = plain login + +# Base d'utilisateurs : un fichier passwd-file +passdb { + driver = passwd-file + args = scheme=PLAIN username_format=%u /etc/dovecot/users +} +userdb { + driver = static + args = uid=5000 gid=5000 home=/var/mail/vhosts/%d/%n +} + +# Désactiver SSL pour l'instant (on l'ajoutera proprement après) +ssl = no + +# Logs vers la sortie standard (pratique pour podman logs) +log_path = /dev/stderr diff --git a/dovecot/users b/dovecot/users new file mode 100644 index 0000000..15f6820 --- /dev/null +++ b/dovecot/users @@ -0,0 +1,2 @@ +alice@ayoinc.test:{PLAIN}alice +bob@ayoinc.test:{PLAIN}bob diff --git a/postfix/Dockerfile b/postfix/Dockerfile new file mode 100644 index 0000000..c5ad728 --- /dev/null +++ b/postfix/Dockerfile @@ -0,0 +1,43 @@ +# Image de base Alpine, légère +FROM alpine:3.21 + +# Installer Postfix et les outils +RUN apk add --no-cache postfix postfix-pcre rsyslog + +# --- Utilisateur dédié au stockage des mails virtuels --- +# Tous les mails appartiendront à cet utilisateur "vmail" (uid/gid 5000) +# Supprimer le vmail créé par défaut par Postfix, puis recréer le nôtre en uid/gid 5000 +RUN (deluser vmail 2>/dev/null || true) \ + && (delgroup vmail 2>/dev/null || true) \ + && addgroup -g 5000 vmail \ + && adduser -D -u 5000 -G vmail -h /var/mail/vhosts vmail \ + && mkdir -p /var/mail/vhosts/ayoinc.test \ + && chown -R vmail:vmail /var/mail/vhosts +# --- Configuration Postfix de base --- +RUN postconf -e "myhostname = mail.ayoinc.test" \ + && postconf -e "mydomain = ayoinc.test" \ + && postconf -e "myorigin = \$mydomain" \ + # Postfix ne gère PAS lui-même notre domaine en "local" : c'est du virtuel + && postconf -e "mydestination = localhost" \ + && postconf -e "inet_interfaces = all" \ + && postconf -e "inet_protocols = ipv4" + +# --- Configuration des boîtes virtuelles --- +RUN postconf -e "virtual_mailbox_domains = ayoinc.test" \ + && postconf -e "virtual_mailbox_base = /var/mail/vhosts" \ + && postconf -e "virtual_mailbox_maps = lmdb:/etc/postfix/vmailbox" \ + && postconf -e "virtual_minimum_uid = 5000" \ + && postconf -e "virtual_uid_maps = static:5000" \ + && postconf -e "virtual_gid_maps = static:5000" + +# --- Déclaration des comptes virtuels (alice & bob) --- +# Chaque ligne : adresse -> chemin Maildir (le / final = format Maildir) +RUN echo "alice@ayoinc.test ayoinc.test/alice/" > /etc/postfix/vmailbox \ + && echo "bob@ayoinc.test ayoinc.test/bob/" >> /etc/postfix/vmailbox \ + && postmap lmdb:/etc/postfix/vmailbox + +# Exposer le port SMTP +EXPOSE 25 + +# Lancer Postfix au premier plan +CMD ["postfix", "start-fg"]