diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..31a063a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.9' + +services: + dovecot: + build: + context: . + dockerfile: dovecot/Dockerfile + container_name: mailstack-dovecot + ports: + - "1143:143" # IMAP + - "1993:993" # IMAPS + volumes: + - vmail:/var/mail/vhosts + networks: + - mailstack + + postfix: + build: + context: . + dockerfile: postfix/Dockerfile + container_name: mailstack-postfix + ports: + - "1025:25" # SMTP + - "1587:587" # SMTP + AUTH + - "1465:465" # SMTPS + volumes: + - vmail:/var/mail/vhosts + networks: + - mailstack + depends_on: + - dovecot + +volumes: + vmail: + +networks: + mailstack: + driver: bridge diff --git a/dovecot/Dockerfile b/dovecot/Dockerfile index 9a3c7e6..fd0a3f8 100644 --- a/dovecot/Dockerfile +++ b/dovecot/Dockerfile @@ -1,22 +1,17 @@ -# Image de base Alpine -FROM alpine:3.21 +FROM debian:bookworm-slim -# Installer Dovecot (IMAP/POP3) + le module d'authentification -RUN apk add --no-cache dovecot +RUN apt-get update && apt-get install -y dovecot-core dovecot-imapd -# --- 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 +RUN mkdir -p /var/mail/vhosts && \ + useradd -m -u 5000 -d /var/mail/vhosts vmail || true -# --- Copier nos fichiers de config dans l'image --- -COPY dovecot.conf /etc/dovecot/dovecot.conf -COPY users /etc/dovecot/users +COPY ../share/users.txt /tmp/users.txt +COPY ../share/dovecot.sh /tmp/dovecot.sh + +RUN chmod +x /tmp/dovecot.sh && \ + /tmp/dovecot.sh > /etc/dovecot/users && \ + rm /tmp/users.txt /tmp/dovecot.sh -# Exposer les ports IMAP EXPOSE 143 993 -# Lancer Dovecot au premier plan CMD ["dovecot", "-F"] diff --git a/postfix/Dockerfile b/postfix/Dockerfile index c5ad728..c4c8a40 100644 --- a/postfix/Dockerfile +++ b/postfix/Dockerfile @@ -1,43 +1,18 @@ -# Image de base Alpine, légère -FROM alpine:3.21 +FROM debian:bookworm-slim -# Installer Postfix et les outils -RUN apk add --no-cache postfix postfix-pcre rsyslog +RUN apt-get update && apt-get install -y postfix mailutils -# --- 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" +COPY ../share/users.txt /tmp/users.txt +COPY ../share/postfix.sh /tmp/postfix.sh +COPY postfix/main.cf /etc/postfix/main.cf +COPY postfix/entrypoint.sh /entrypoint.sh -# --- 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" +RUN chmod 644 /etc/postfix/main.cf && \ + chmod +x /tmp/postfix.sh /entrypoint.sh && \ + /tmp/postfix.sh > /etc/postfix/virtual_mailbox && \ + postmap /etc/postfix/virtual_mailbox && \ + rm /tmp/users.txt /tmp/postfix.sh -# --- 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 +EXPOSE 25 587 -# Exposer le port SMTP -EXPOSE 25 - -# Lancer Postfix au premier plan -CMD ["postfix", "start-fg"] +CMD ["/entrypoint.sh"] diff --git a/postfix/entrypoint.sh b/postfix/entrypoint.sh new file mode 100755 index 0000000..931e7f2 --- /dev/null +++ b/postfix/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +postfix start +tail -f /dev/null diff --git a/postfix/main.cf b/postfix/main.cf new file mode 100644 index 0000000..0e40e46 --- /dev/null +++ b/postfix/main.cf @@ -0,0 +1,15 @@ +myhostname = mail.ayoinc.test +myorigin = ayoinc.test +mydestination = localhost +mynetworks = 127.0.0.0/8 [::1]/128 +inet_interfaces = all + +virtual_mailbox_domains = ayoinc.test +virtual_mailbox_base = /var/mail/vhosts +virtual_mailbox_maps = hash:/etc/postfix/virtual_mailbox +virtual_uid_maps = static:5000 +virtual_gid_maps = static:5000 +virtual_transport = virtual + +smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination +maillog_file = /dev/stdout diff --git a/share/dovecot.sh b/share/dovecot.sh index 02b98dc..fb01f71 100755 --- a/share/dovecot.sh +++ b/share/dovecot.sh @@ -3,4 +3,4 @@ while IFS= read -r email; do username="${email%@*}" echo "${email}:{PLAIN}${username}" -done < users.txt +done < /tmp/users.txt diff --git a/share/postfix.sh b/share/postfix.sh index cca782d..47933bd 100755 --- a/share/postfix.sh +++ b/share/postfix.sh @@ -4,4 +4,4 @@ while IFS= read -r email; do username="${email%@*}" domain="${email#*@}" echo "${email} ${domain}/${username}/" -done < users.txt +done < /tmp/users.txt