2021-01-16 10:16:05 +01:00
FROM docker.io/debian:buster-slim
2019-10-23 11:22:23 +02:00
2021-01-16 10:16:05 +01:00
ARG VCS_VER
2019-10-23 11:22:23 +02:00
ARG VCS_REF
2021-01-16 10:16:05 +01:00
ARG DEBIAN_FRONTEND = noninteractive
2019-10-23 11:22:23 +02:00
2021-05-15 11:11:10 +02:00
ARG FAIL2BAN_DEB_URL = https://github.com/fail2ban/fail2ban/releases/download/0.11.2/fail2ban_0.11.2-1.upstream1_all.deb
ARG FAIL2BAN_DEB_ASC_URL = ${ FAIL2BAN_DEB_URL } .asc
ARG FAIL2BAN_GPG_PUBLIC_KEY_ID = 0x683BF1BEBD0A882C
2021-06-22 10:37:44 +02:00
ARG FAIL2BAN_GPG_PUBLIC_KEY_SERVER = hkps://keyserver.ubuntu.com
2021-05-15 11:11:10 +02:00
ARG FAIL2BAN_GPG_FINGERPRINT = "8738 559E 26F6 71DF 9E2C 6D9E 683B F1BE BD0A 882C"
2021-01-16 10:16:05 +01:00
LABEL org.opencontainers.image.version= ${ VCS_VER }
LABEL org.opencontainers.image.revision= ${ VCS_REF }
LABEL org.opencontainers.image.title= "docker-mailserver"
LABEL org.opencontainers.image.vendor= "The Docker Mailserver Organization"
LABEL org.opencontainers.image.authors= "The Docker Mailserver Organization on GitHub"
LABEL org.opencontainers.image.licenses= "MIT"
LABEL org.opencontainers.image.description= "A fullstack but simple mail server (SMTP, IMAP, LDAP, Antispam, Antivirus, etc.). Only configuration files, no SQL database."
LABEL org.opencontainers.image.url= "https://github.com/docker-mailserver"
LABEL org.opencontainers.image.documentation= "https://github.com/docker-mailserver/docker-mailserver/blob/master/README.md"
LABEL org.opencontainers.image.source= "https://github.com/docker-mailserver/docker-mailserver"
2015-03-28 15:59:15 +01:00
2017-08-07 17:39:40 +02:00
ENV ENABLE_POSTGREY = 0
2017-10-04 13:10:18 -07:00
ENV FETCHMAIL_POLL = 300
2021-08-31 13:50:56 +02:00
ENV ONE_DIR = 1
2021-01-16 10:16:05 +01:00
ENV POSTGREY_AUTO_WHITELIST_CLIENTS = 5
2017-08-07 17:39:40 +02:00
ENV POSTGREY_DELAY = 300
ENV POSTGREY_MAX_AGE = 35
2021-01-16 10:16:05 +01:00
ENV POSTGREY_TEXT = "Delayed by Postgrey"
2017-08-07 17:39:40 +02:00
ENV SASLAUTHD_MECHANISMS = pam
ENV SASLAUTHD_MECH_OPTIONS = ""
2021-01-16 10:16:05 +01:00
ENV VIRUSMAILS_DELETE_DELAY = 7
2017-03-14 15:22:19 +01:00
2019-08-13 11:41:38 +02:00
SHELL [ "/bin/bash" , "-o" , "pipefail" , "-c" ]
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- Install Basic Software --------------------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
2019-12-31 16:34:21 +01:00
RUN \
2021-07-05 03:25:26 -07:00
# Backport repo for dovecot-fts-xapian package. This can be removed once Debian 11 is used as base image.
echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/buster-backports.list && \
2021-02-21 23:36:09 +01:00
apt-get -qq update && \
2021-06-09 01:07:01 +02:00
apt-get -qq install apt-utils 2>/dev/null && \
apt-get -qq dist-upgrade && \
apt-get -qq install postfix && \
apt-get -qq --no-install-recommends install \
2021-01-18 20:51:56 +01:00
# A - D
2021-05-19 21:18:06 +02:00
altermime amavisd-new apt-transport-https arj binutils bzip2 bsd-mailx \
2021-02-23 20:03:01 +01:00
ca-certificates cabextract clamav clamav-daemon cpio curl \
2021-07-05 03:25:26 -07:00
dbconfig-no-thanks dovecot-core dovecot-fts-xapian dovecot-imapd \
dovecot-ldap dovecot-lmtpd dovecot-managesieved dovecot-pop3d \
dovecot-sieve dovecot-solr dumb-init \
2021-01-18 20:51:56 +01:00
# E - O
2021-05-15 11:11:10 +02:00
ed fetchmail file gamin gnupg gzip iproute2 iptables \
2021-01-16 10:16:05 +01:00
locales logwatch lhasa libdate-manip-perl liblz4-tool \
libmail-spf-perl libnet-dns-perl libsasl2-modules lrzip lzop \
netcat-openbsd nomarch opendkim opendkim-tools opendmarc \
# P - Z
pax pflogsumm postgrey p7zip-full postfix-ldap postfix-pcre \
postfix-policyd-spf-python postsrsd pyzor \
razor rpm2cpio rsyslog sasl2-bin spamassassin supervisor \
2021-09-13 04:09:01 -04:00
unrar-free unzip uuid whois xz-utils && \
2021-05-15 11:11:10 +02:00
# Fail2Ban
gpg --keyserver ${ FAIL2BAN_GPG_PUBLIC_KEY_SERVER } \
2021-06-08 03:20:20 +02:00
--recv-keys ${ FAIL2BAN_GPG_PUBLIC_KEY_ID } 2>& 1 && \
2021-05-16 21:05:39 +02:00
curl -Lkso fail2ban.deb ${ FAIL2BAN_DEB_URL } && \
curl -Lkso fail2ban.deb.asc ${ FAIL2BAN_DEB_ASC_URL } && \
2021-05-15 11:11:10 +02:00
FINGERPRINT = " $( LANG = C gpg --verify \
fail2ban.deb.asc fail2ban.deb 2>& 1 \
| sed -n 's#Primary key fingerprint: \(.*\)#\1#p' ) " && \
if [ [ -z ${ FINGERPRINT } ] ] ; then \
2021-06-08 03:20:20 +02:00
echo "ERROR: Invalid GPG signature!" >& 2; exit 1; fi && \
2021-05-15 11:11:10 +02:00
if [ [ ${ FINGERPRINT } != " ${ FAIL2BAN_GPG_FINGERPRINT } " ] ] ; then \
2021-06-08 03:20:20 +02:00
echo "ERROR: Wrong GPG fingerprint!" >& 2; exit 1; fi && \
dpkg -i fail2ban.deb 2>& 1 && \
2021-05-15 11:11:10 +02:00
rm fail2ban.deb fail2ban.deb.asc && \
2021-01-16 10:16:05 +01:00
# cleanup
2021-06-08 03:20:20 +02:00
apt-get -qq autoremove && \
2021-01-16 10:16:05 +01:00
apt-get -qq autoclean && \
apt-get -qq clean && \
2017-07-23 19:38:34 +02:00
rm -rf /var/lib/apt/lists/* && \
2021-06-08 03:20:20 +02:00
c_rehash 2>& 1
2021-01-16 10:16:05 +01:00
2021-09-06 00:07:02 +02:00
# -----------------------------------------------
# --- Scripts -----------------------------------
# -----------------------------------------------
COPY \
./target/bin/* \
./target/scripts/*.sh \
./target/scripts/startup/*.sh \
./target/docker-configomat/configomat.sh \
/usr/local/bin/
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- ClamAV & FeshClam -------------------------
# -----------------------------------------------
2015-03-28 15:59:15 +01:00
2021-01-16 10:16:05 +01:00
RUN \
2021-05-15 11:11:10 +02:00
echo '0 */6 * * * clamav /usr/bin/freshclam --quiet' >/etc/cron.d/clamav-freshclam && \
2017-07-23 19:38:34 +02:00
chmod 644 /etc/clamav/freshclam.conf && \
2017-08-07 17:39:40 +02:00
freshclam && \
2021-09-06 00:07:02 +02:00
sedfile -i 's/Foreground false/Foreground true/g' /etc/clamav/clamd.conf && \
2017-08-07 17:39:40 +02:00
mkdir /var/run/clamav && \
2020-01-15 08:29:39 -05:00
chown -R clamav:root /var/run/clamav && \
rm -rf /var/log/clamav/
2016-10-08 19:02:47 +02:00
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- Dovecot & MkCert --------------------------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
2017-07-23 19:38:34 +02:00
COPY target/dovecot/auth-passwdfile.inc target/dovecot/??-*.conf /etc/dovecot/conf.d/
2020-05-04 00:24:10 +02:00
COPY target/dovecot/sieve/ /etc/dovecot/sieve/
2020-12-06 19:57:38 +01:00
COPY target/dovecot/dovecot-purge.cron /etc/cron.d/dovecot-purge.disabled
RUN chmod 0 /etc/cron.d/dovecot-purge.disabled
2019-08-13 11:41:38 +02:00
WORKDIR /usr/share/dovecot
2021-01-16 10:16:05 +01:00
# hadolint ignore=SC2016,SC2086,SC2069
RUN \
2021-09-06 00:07:02 +02:00
sedfile -i -e 's/include_try \/usr\/share\/dovecot\/protocols\.d/include_try \/etc\/dovecot\/protocols\.d/g' /etc/dovecot/dovecot.conf && \
sedfile -i -e 's/#mail_plugins = \$mail_plugins/mail_plugins = \$mail_plugins sieve/g' /etc/dovecot/conf.d/15-lda.conf && \
sedfile -i -e 's/^.*lda_mailbox_autocreate.*/lda_mailbox_autocreate = yes/g' /etc/dovecot/conf.d/15-lda.conf && \
sedfile -i -e 's/^.*lda_mailbox_autosubscribe.*/lda_mailbox_autosubscribe = yes/g' /etc/dovecot/conf.d/15-lda.conf && \
sedfile -i -e 's/^.*postmaster_address.*/postmaster_address = ' ${ POSTMASTER_ADDRESS : = "postmaster@domain.com" } '/g' /etc/dovecot/conf.d/15-lda.conf && \
sedfile -i 's/RANDFILE.*//g' /usr/share/dovecot/dovecot-openssl.cnf && \
2018-02-04 21:27:47 +01:00
mkdir /etc/dovecot/ssl && \
2021-01-16 10:16:05 +01:00
chmod 755 /etc/dovecot/ssl && \
2021-06-08 03:20:20 +02:00
./mkcert.sh 2>& 1 && \
2018-04-05 18:54:01 +02:00
mkdir -p /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global && \
2019-08-09 22:13:50 +02:00
chmod 755 -R /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global
2015-03-29 14:07:56 +02:00
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- LDAP & SpamAssassin's Cron ----------------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
2016-11-13 11:39:45 +01:00
COPY target/dovecot/dovecot-ldap.conf.ext /etc/dovecot
2021-01-16 10:16:05 +01:00
COPY \
target/postfix/ldap-users.cf \
target/postfix/ldap-groups.cf \
target/postfix/ldap-aliases.cf \
target/postfix/ldap-domains.cf \
2021-04-17 22:40:19 +02:00
target/postfix/ldap-senders.cf \
2021-01-16 10:16:05 +01:00
/etc/postfix/
2016-11-13 11:39:45 +01:00
2019-08-13 11:41:38 +02:00
# hadolint ignore=SC2016
2021-01-16 10:16:05 +01:00
RUN \
2021-09-06 00:07:02 +02:00
sedfile -i -r 's/^(CRON)=0/\1=1/g' /etc/default/spamassassin && \
sedfile -i -r 's/^\$INIT restart/supervisorctl restart amavis/g' /etc/spamassassin/sa-update-hooks.d/amavisd-new
2015-03-28 15:59:15 +01:00
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
2021-09-06 00:07:02 +02:00
# --- Miscellaneous -----------------------------
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
2021-05-19 21:18:06 +02:00
COPY \
./VERSION /
2021-01-16 10:16:05 +01:00
RUN \
chmod +x /usr/local/bin/* && \
rm -rf /usr/share/locale/* && \
rm -rf /usr/share/man/* && \
rm -rf /usr/share/doc/* && \
touch /var/log/auth.log && \
update-locale && \
rm /etc/postsrsd.secret && \
2021-05-19 21:18:06 +02:00
rm /etc/cron.daily/00logwatch
2021-01-16 10:16:05 +01:00
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- PostSRSD, Postgrey & Amavis ---------------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
COPY target/postsrsd/postsrsd /etc/default/postsrsd
2017-02-06 09:21:18 +00:00
COPY target/postgrey/postgrey /etc/default/postgrey
COPY target/postgrey/postgrey.init /etc/init.d/postgrey
2021-01-16 10:16:05 +01:00
RUN \
chmod 755 /etc/init.d/postgrey && \
2017-07-23 19:38:34 +02:00
mkdir /var/run/postgrey && \
2021-06-17 18:16:28 +02:00
chown postgrey:postgrey /var/run/postgrey && \
curl -Lsfo /etc/postgrey/whitelist_clients https://postgrey.schweikert.ch/pub/postgrey_whitelist_clients
2017-02-06 09:21:18 +00:00
2017-08-09 23:19:00 +02:00
COPY target/amavis/conf.d/* /etc/amavis/conf.d/
2021-01-16 10:16:05 +01:00
RUN \
2021-09-06 00:07:02 +02:00
sedfile -i -r 's/#(@| \\%)bypass/\1bypass/g' /etc/amavis/conf.d/15-content_filter_mode && \
2021-06-08 03:20:20 +02:00
adduser clamav amavis && \
adduser amavis clamav && \
2021-01-18 20:51:56 +01:00
# no syslog user in Debian compared to Ubuntu
2021-06-08 03:20:20 +02:00
adduser --system syslog && \
useradd -u 5000 -d /home/docker -s /bin/bash -p " $( echo docker | openssl passwd -1 -stdin) " docker && \
2020-10-01 13:54:43 +02:00
echo "0 4 * * * /usr/local/bin/virus-wiper" | crontab - && \
2020-10-05 17:11:15 +02:00
chmod 644 /etc/amavis/conf.d/*
2015-03-28 15:59:15 +01:00
2021-01-19 15:32:16 +01:00
# overcomplication necessary for CI
2021-04-11 17:33:39 +02:00
RUN \
for _ in { 1..10} ; do su - amavis -c "razor-admin -create" ; sleep 3 ; \
2021-06-08 03:20:20 +02:00
if su - amavis -c "razor-admin -register" ; then { EC = 0 ; break ; } ; \
2021-01-19 15:32:16 +01:00
else EC = ${ ? } ; fi ; done ; ( exit ${ EC } )
2021-01-16 10:16:05 +01:00
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- Fail2Ban, DKIM & DMARC --------------------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
2021-04-11 17:33:39 +02:00
COPY target/fail2ban/jail.local /etc/fail2ban/jail.local
RUN \
ln -s /var/log/mail/mail.log /var/log/mail.log && \
# disable sshd jail
rm /etc/fail2ban/jail.d/defaults-debian.conf && \
mkdir /var/run/fail2ban
2016-04-17 22:59:35 +02:00
2016-09-04 20:37:16 +02:00
COPY target/opendkim/opendkim.conf /etc/opendkim.conf
COPY target/opendkim/default-opendkim /etc/default/opendkim
2016-01-20 16:41:34 +01:00
2016-09-04 20:37:16 +02:00
COPY target/opendmarc/opendmarc.conf /etc/opendmarc.conf
COPY target/opendmarc/default-opendmarc /etc/default/opendmarc
2016-10-25 09:57:08 +03:00
COPY target/opendmarc/ignore.hosts /etc/opendmarc/ignore.hosts
2016-01-26 18:26:50 +01:00
2021-01-16 10:16:05 +01:00
RUN \
2021-01-18 20:51:56 +01:00
# switch iptables and ip6tables to legacy for Fail2Ban
2021-01-16 10:16:05 +01:00
update-alternatives --set iptables /usr/sbin/iptables-legacy && \
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
2016-08-21 22:13:13 +02:00
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- Fetchmail, Postfix & Let'sEncrypt ---------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
COPY target/fetchmail/fetchmailrc /etc/fetchmailrc_general
2016-09-04 20:37:16 +02:00
COPY target/postfix/main.cf target/postfix/master.cf /etc/postfix/
2021-09-15 20:28:04 +12:00
# DH parameters for DHE cipher suites, ffdhe4096 is the official standard 4096-bit DH params now part of TLS 1.3
# This file is for TLS <1.3 handshakes that rely on DHE cipher suites
# Handled at build to avoid failures by doveadm validating ssl_dh filepath in 10-ssl.auth (eg generate-accounts)
COPY target/shared/ffdhe4096.pem /etc/postfix/dhparams.pem
COPY target/shared/ffdhe4096.pem /etc/dovecot/dh.pem
2021-01-16 10:16:05 +01:00
COPY \
target/postfix/header_checks.pcre \
target/postfix/sender_header_filter.pcre \
target/postfix/sender_login_maps.pcre \
/etc/postfix/maps/
2015-03-31 17:27:54 +02:00
2021-01-16 10:16:05 +01:00
RUN \
: >/etc/aliases && \
2021-09-06 00:07:02 +02:00
sedfile -i 's/START_DAEMON=no/START_DAEMON=yes/g' /etc/default/fetchmail && \
2021-01-16 10:16:05 +01:00
mkdir /var/run/fetchmail && chown fetchmail /var/run/fetchmail && \
curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem >/etc/ssl/certs/lets-encrypt-x3-cross-signed.pem
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- Logs --------------------------------------
# -----------------------------------------------
2021-01-16 10:16:05 +01:00
RUN \
2021-09-06 00:07:02 +02:00
sedfile -i -r "/^#?compress/c\compress\ncopytruncate" /etc/logrotate.conf && \
2017-07-23 19:38:34 +02:00
mkdir -p /var/log/mail && \
chown syslog:root /var/log/mail && \
touch /var/log/mail/clamav.log && \
chown -R clamav:root /var/log/mail/clamav.log && \
touch /var/log/mail/freshclam.log && \
chown -R clamav:root /var/log/mail/freshclam.log && \
2021-09-06 00:07:02 +02:00
sedfile -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/rsyslog.conf && \
sedfile -i -r 's|;auth,authpriv.none|;mail.none;mail.error;auth,authpriv.none|g' /etc/rsyslog.conf && \
sedfile -i -r 's|LogFile /var/log/clamav/|LogFile /var/log/mail/|g' /etc/clamav/clamd.conf && \
sedfile -i -r 's|UpdateLogFile /var/log/clamav/|UpdateLogFile /var/log/mail/|g' /etc/clamav/freshclam.conf && \
sedfile -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-daemon && \
sedfile -i -r 's|invoke-rc.d.*|/usr/bin/supervisorctl signal hup clamav >/dev/null \|\| true|g' /etc/logrotate.d/clamav-daemon && \
sedfile -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-freshclam && \
sedfile -i -r '/postrotate/,/endscript/d' /etc/logrotate.d/clamav-freshclam && \
sedfile -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/logrotate.d/rsyslog && \
sedfile -i -r '/\/var\/log\/mail\/mail.log/d' /etc/logrotate.d/rsyslog && \
2021-01-18 20:51:56 +01:00
# prevent syslog logrotate warnings
2021-09-06 00:07:02 +02:00
sedfile -i -e 's/\(printerror "could not determine current runlevel"\)/#\1/' /usr/sbin/invoke-rc.d && \
sedfile -i -e 's/^\(POLICYHELPER=\).*/\1/' /usr/sbin/invoke-rc.d && \
2021-01-16 10:16:05 +01:00
# prevent syslog warning about imklog permissions
2021-09-06 00:07:02 +02:00
sedfile -i -e 's/^module(load=\"imklog\")/#module(load=\"imklog\")/' /etc/rsyslog.conf && \
2021-01-18 20:51:56 +01:00
# prevent email when /sbin/init or init system is not existing
2021-09-06 00:07:02 +02:00
sedfile -i -e 's|invoke-rc.d rsyslog rotate > /dev/null|/usr/bin/supervisorctl signal hup rsyslog >/dev/null|g' /usr/lib/rsyslog/rsyslog-rotate
2016-04-18 23:38:52 +02:00
2021-08-11 05:31:00 -04:00
# -----------------------------------------------
# --- Logwatch ----------------------------------
# -----------------------------------------------
COPY target/logwatch/maillog.conf /etc/logwatch/conf/logfiles/maillog.conf
2021-06-08 03:20:20 +02:00
# -----------------------------------------------
# --- Supervisord & Start -----------------------
# -----------------------------------------------
2016-02-08 23:47:42 +01:00
2017-09-10 15:26:21 +02:00
COPY target/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY target/supervisor/conf.d/* /etc/supervisor/conf.d/
2016-01-23 19:51:09 -03:00
2019-08-13 11:41:38 +02:00
WORKDIR /
2017-09-07 18:08:25 +02:00
EXPOSE 25 587 143 465 993 110 995 4190
2016-09-29 22:52:05 +02:00
2021-01-16 19:35:42 +01:00
ENTRYPOINT [ "/usr/bin/dumb-init" , "--" ]
2018-11-04 20:23:50 +01:00
CMD [ "supervisord" , "-c" , "/etc/supervisor/supervisord.conf" ]