2021-01-16 09:16:05 +00:00
FROM docker.io/debian:buster-slim
2019-10-23 09:22:23 +00:00
2021-01-16 09:16:05 +00:00
ARG VCS_VER
2019-10-23 09:22:23 +00:00
ARG VCS_REF
2021-01-16 09:16:05 +00:00
ARG DEBIAN_FRONTEND = noninteractive
2019-10-23 09:22:23 +00:00
2021-05-15 09:11:10 +00: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
ARG FAIL2BAN_GPG_PUBLIC_KEY_SERVER = keys.gnupg.net
ARG FAIL2BAN_GPG_FINGERPRINT = "8738 559E 26F6 71DF 9E2C 6D9E 683B F1BE BD0A 882C"
2021-01-16 09:16:05 +00: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 14:59:15 +00:00
2017-08-07 15:39:40 +00:00
ENV ENABLE_POSTGREY = 0
2017-10-04 20:10:18 +00:00
ENV FETCHMAIL_POLL = 300
2021-01-16 09:16:05 +00:00
ENV ONE_DIR = 0
ENV POSTGREY_AUTO_WHITELIST_CLIENTS = 5
2017-08-07 15:39:40 +00:00
ENV POSTGREY_DELAY = 300
ENV POSTGREY_MAX_AGE = 35
2021-01-16 09:16:05 +00:00
ENV POSTGREY_TEXT = "Delayed by Postgrey"
2017-08-07 15:39:40 +00:00
ENV SASLAUTHD_MECHANISMS = pam
ENV SASLAUTHD_MECH_OPTIONS = ""
2021-01-16 09:16:05 +00:00
ENV VIRUSMAILS_DELETE_DELAY = 7
2017-03-14 14:22:19 +00:00
2019-08-13 09:41:38 +00:00
SHELL [ "/bin/bash" , "-o" , "pipefail" , "-c" ]
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – Install Basic Software – – – – – – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2019-12-31 15:34:21 +00:00
RUN \
2021-02-21 22:36:09 +00:00
apt-get -qq update && \
2021-01-16 09:16:05 +00:00
apt-get -y install apt-utils & >/dev/null && \
2021-02-07 17:11:33 +00:00
apt-get -y dist-upgrade >/dev/null && \
2021-01-16 09:16:05 +00:00
apt-get -y install postfix >/dev/null && \
apt-get -y --no-install-recommends install \
2021-01-18 19:51:56 +00:00
# A - D
2021-05-19 19:18:06 +00:00
altermime amavisd-new apt-transport-https arj binutils bzip2 bsd-mailx \
2021-02-23 19:03:01 +00:00
ca-certificates cabextract clamav clamav-daemon cpio curl \
2021-01-16 09:16:05 +00:00
dovecot-core dovecot-imapd dovecot-ldap dovecot-lmtpd \
dovecot-managesieved dovecot-pop3d dovecot-sieve dovecot-solr \
2021-02-23 19:03:01 +00:00
dumb-init \
2021-01-18 19:51:56 +00:00
# E - O
2021-05-15 09:11:10 +00:00
ed fetchmail file gamin gnupg gzip iproute2 iptables \
2021-01-16 09:16:05 +00: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-05-19 19:18:06 +00:00
unrar-free unzip whois xz-utils && \
2021-05-15 09:11:10 +00:00
# Fail2Ban
gpg --keyserver ${ FAIL2BAN_GPG_PUBLIC_KEY_SERVER } \
--recv-keys ${ FAIL2BAN_GPG_PUBLIC_KEY_ID } & >/dev/null && \
2021-05-16 19:05:39 +00:00
curl -Lkso fail2ban.deb ${ FAIL2BAN_DEB_URL } && \
curl -Lkso fail2ban.deb.asc ${ FAIL2BAN_DEB_ASC_URL } && \
2021-05-15 09:11:10 +00: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 \
echo "ERROR: Invalid GPG signature!" 2>& 1; exit 1; fi && \
if [ [ ${ FINGERPRINT } != " ${ FAIL2BAN_GPG_FINGERPRINT } " ] ] ; then \
echo "ERROR: Wrong GPG fingerprint!" 2>& 1; exit 1; fi && \
dpkg -i fail2ban.deb & >/dev/null && \
rm fail2ban.deb fail2ban.deb.asc && \
2021-01-16 09:16:05 +00:00
# cleanup
2021-05-15 09:11:10 +00:00
apt-get -qq autoremove & >/dev/null && \
2021-01-16 09:16:05 +00:00
apt-get -qq autoclean && \
apt-get -qq clean && \
2017-07-23 17:38:34 +00:00
rm -rf /var/lib/apt/lists/* && \
2021-05-15 09:11:10 +00:00
c_rehash & >/dev/null
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – ClamAV & FeshClam – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2015-03-28 14:59:15 +00:00
2021-01-16 09:16:05 +00:00
RUN \
2021-05-15 09:11:10 +00:00
echo '0 */6 * * * clamav /usr/bin/freshclam --quiet' >/etc/cron.d/clamav-freshclam && \
2017-07-23 17:38:34 +00:00
chmod 644 /etc/clamav/freshclam.conf && \
2017-08-07 15:39:40 +00:00
freshclam && \
sed -i 's/Foreground false/Foreground true/g' /etc/clamav/clamd.conf && \
mkdir /var/run/clamav && \
2020-01-15 13:29:39 +00:00
chown -R clamav:root /var/run/clamav && \
rm -rf /var/log/clamav/
2016-10-08 17:02:47 +00:00
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2021-01-18 19:51:56 +00:00
# – – – Dovecot & MkCert – – – – – – – – – – – – – – – – – – – – – – – – – –
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2017-07-23 17:38:34 +00:00
COPY target/dovecot/auth-passwdfile.inc target/dovecot/??-*.conf /etc/dovecot/conf.d/
2020-05-03 22:24:10 +00:00
COPY target/dovecot/sieve/ /etc/dovecot/sieve/
2020-12-06 18:57:38 +00: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 09:41:38 +00:00
WORKDIR /usr/share/dovecot
2021-01-16 09:16:05 +00:00
# hadolint ignore=SC2016,SC2086,SC2069
RUN \
sed -i -e 's/include_try \/usr\/share\/dovecot\/protocols\.d/include_try \/etc\/dovecot\/protocols\.d/g' /etc/dovecot/dovecot.conf && \
2017-07-23 17:38:34 +00:00
sed -i -e 's/#mail_plugins = \$mail_plugins/mail_plugins = \$mail_plugins sieve/g' /etc/dovecot/conf.d/15-lda.conf && \
sed -i -e 's/^.*lda_mailbox_autocreate.*/lda_mailbox_autocreate = yes/g' /etc/dovecot/conf.d/15-lda.conf && \
sed -i -e 's/^.*lda_mailbox_autosubscribe.*/lda_mailbox_autosubscribe = yes/g' /etc/dovecot/conf.d/15-lda.conf && \
sed -i -e 's/^.*postmaster_address.*/postmaster_address = ' ${ POSTMASTER_ADDRESS : = "postmaster@domain.com" } '/g' /etc/dovecot/conf.d/15-lda.conf && \
sed -i 's/#imap_idle_notify_interval = 2 mins/imap_idle_notify_interval = 29 mins/' /etc/dovecot/conf.d/20-imap.conf && \
2021-01-16 09:16:05 +00:00
# adapt mkcert for Dovecot community repo
2019-08-31 07:15:42 +00:00
sed -i 's/CERTDIR=.*/CERTDIR=\/etc\/dovecot\/ssl/g' /usr/share/dovecot/mkcert.sh && \
sed -i 's/KEYDIR=.*/KEYDIR=\/etc\/dovecot\/ssl/g' /usr/share/dovecot/mkcert.sh && \
sed -i 's/KEYFILE=.*/KEYFILE=\$KEYDIR\/dovecot.key/g' /usr/share/dovecot/mkcert.sh && \
2021-01-16 09:16:05 +00:00
sed -i 's/RANDFILE.*//g' /usr/share/dovecot/dovecot-openssl.cnf && \
2018-02-04 20:27:47 +00:00
mkdir /etc/dovecot/ssl && \
2021-01-16 09:16:05 +00:00
chmod 755 /etc/dovecot/ssl && \
./mkcert.sh 2>& 1 >/dev/null && \
2018-04-05 16:54:01 +00:00
mkdir -p /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global && \
2019-08-09 20:13:50 +00:00
chmod 755 -R /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global
2015-03-29 12:07:56 +00:00
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2021-03-28 20:07:52 +00:00
# – – – LDAP & SpamAssassin's Cron – – – – – – – – – – – – – – – –
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2016-11-13 10:39:45 +00:00
COPY target/dovecot/dovecot-ldap.conf.ext /etc/dovecot
2021-01-16 09:16:05 +00: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 20:40:19 +00:00
target/postfix/ldap-senders.cf \
2021-01-16 09:16:05 +00:00
/etc/postfix/
2016-11-13 10:39:45 +00:00
2019-08-13 09:41:38 +00:00
# hadolint ignore=SC2016
2021-01-16 09:16:05 +00:00
RUN \
sed -i -r 's/^(CRON)=0/\1=1/g' /etc/default/spamassassin && \
2020-09-24 12:54:21 +00:00
sed -i -r 's/^\$INIT restart/supervisorctl restart amavis/g' /etc/spamassassin/sa-update-hooks.d/amavisd-new
2015-03-28 14:59:15 +00:00
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – Scripts & Miscellaneous – – – – – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
COPY \
./target/bin/* \
./target/scripts/*.sh \
2021-02-23 19:03:01 +00:00
./target/scripts/startup/*.sh \
2021-01-16 09:16:05 +00:00
./target/docker-configomat/configomat.sh \
/usr/local/bin/
2021-05-19 19:18:06 +00:00
COPY \
./VERSION /
2021-01-16 09:16:05 +00: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 19:18:06 +00:00
rm /etc/cron.daily/00logwatch
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – PostSRSD, Postgrey & Amavis – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
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 09:16:05 +00:00
RUN \
chmod 755 /etc/init.d/postgrey && \
2017-07-23 17:38:34 +00:00
mkdir /var/run/postgrey && \
chown postgrey:postgrey /var/run/postgrey
2017-02-06 09:21:18 +00:00
2017-08-09 21:19:00 +00:00
COPY target/amavis/conf.d/* /etc/amavis/conf.d/
2021-01-16 09:16:05 +00:00
RUN \
sed -i -r 's/#(@| \\%)bypass/\1bypass/g' /etc/amavis/conf.d/15-content_filter_mode && \
adduser clamav amavis >/dev/null && \
adduser amavis clamav >/dev/null && \
2021-01-18 19:51:56 +00:00
# no syslog user in Debian compared to Ubuntu
2021-01-16 09:16:05 +00:00
adduser --system syslog >/dev/null && \
useradd -u 5000 -d /home/docker -s /bin/bash -p " $( echo docker | openssl passwd -1 -stdin) " docker >/dev/null && \
2020-10-01 11:54:43 +00:00
echo "0 4 * * * /usr/local/bin/virus-wiper" | crontab - && \
2020-10-05 15:11:15 +00:00
chmod 644 /etc/amavis/conf.d/*
2015-03-28 14:59:15 +00:00
2021-01-19 14:32:16 +00:00
# overcomplication necessary for CI
2021-04-11 15:33:39 +00:00
RUN \
for _ in { 1..10} ; do su - amavis -c "razor-admin -create" ; sleep 3 ; \
2021-01-19 14:32:16 +00:00
if su - amavis -c "razor-admin -register" & >/dev/null; then { EC = 0 ; break ; } ; \
else EC = ${ ? } ; fi ; done ; ( exit ${ EC } )
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – Fail2Ban, DKIM & DMARC – – – – – – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2021-04-11 15:33:39 +00: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 20:59:35 +00:00
2016-09-04 18:37:16 +00:00
COPY target/opendkim/opendkim.conf /etc/opendkim.conf
COPY target/opendkim/default-opendkim /etc/default/opendkim
2016-01-20 15:41:34 +00:00
2016-09-04 18:37:16 +00:00
COPY target/opendmarc/opendmarc.conf /etc/opendmarc.conf
COPY target/opendmarc/default-opendmarc /etc/default/opendmarc
2016-10-25 06:57:08 +00:00
COPY target/opendmarc/ignore.hosts /etc/opendmarc/ignore.hosts
2016-01-26 17:26:50 +00:00
2021-01-16 09:16:05 +00:00
RUN \
2021-01-18 19:51:56 +00:00
# switch iptables and ip6tables to legacy for Fail2Ban
2021-01-16 09:16:05 +00:00
update-alternatives --set iptables /usr/sbin/iptables-legacy && \
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
2016-08-21 20:13:13 +00:00
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – Fetchmail, Postfix & Let'sEncrypt – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
COPY target/fetchmail/fetchmailrc /etc/fetchmailrc_general
2016-09-04 18:37:16 +00:00
COPY target/postfix/main.cf target/postfix/master.cf /etc/postfix/
2021-01-16 09:16:05 +00:00
COPY target/shared/ffdhe4096.pem /etc/postfix/shared/ffdhe4096.pem
COPY \
target/postfix/header_checks.pcre \
target/postfix/sender_header_filter.pcre \
target/postfix/sender_login_maps.pcre \
/etc/postfix/maps/
2015-03-31 15:27:54 +00:00
2021-01-16 09:16:05 +00:00
RUN \
: >/etc/aliases && \
sed -i 's/START_DAEMON=no/START_DAEMON=yes/g' /etc/default/fetchmail && \
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
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – Logs – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
RUN \
sed -i -r "/^#?compress/c\compress\ncopytruncate" /etc/logrotate.conf && \
2017-07-23 17:38:34 +00: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 && \
2017-12-31 11:33:48 +00:00
sed -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/rsyslog.conf && \
sed -i -r 's|;auth,authpriv.none|;mail.none;mail.error;auth,authpriv.none|g' /etc/rsyslog.conf && \
2016-04-24 11:46:48 +00:00
sed -i -r 's|LogFile /var/log/clamav/|LogFile /var/log/mail/|g' /etc/clamav/clamd.conf && \
sed -i -r 's|UpdateLogFile /var/log/clamav/|UpdateLogFile /var/log/mail/|g' /etc/clamav/freshclam.conf && \
sed -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-daemon && \
2020-04-11 07:31:53 +00:00
sed -i -r 's|invoke-rc.d.*|/usr/bin/supervisorctl signal hup clamav >/dev/null \|\| true|g' /etc/logrotate.d/clamav-daemon && \
2016-04-24 11:46:48 +00:00
sed -i -r 's|/var/log/clamav|/var/log/mail|g' /etc/logrotate.d/clamav-freshclam && \
2020-05-18 08:08:15 +00:00
sed -i -r '/postrotate/,/endscript/d' /etc/logrotate.d/clamav-freshclam && \
2017-09-12 17:33:52 +00:00
sed -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/logrotate.d/rsyslog && \
2018-04-03 17:28:43 +00:00
sed -i -r '/\/var\/log\/mail\/mail.log/d' /etc/logrotate.d/rsyslog && \
2021-01-18 19:51:56 +00:00
# prevent syslog logrotate warnings
2017-09-12 17:33:52 +00:00
sed -i -e 's/\(printerror "could not determine current runlevel"\)/#\1/' /usr/sbin/invoke-rc.d && \
2018-03-07 18:31:10 +00:00
sed -i -e 's/^\(POLICYHELPER=\).*/\1/' /usr/sbin/invoke-rc.d && \
2021-01-16 09:16:05 +00:00
# prevent syslog warning about imklog permissions
2020-12-09 20:42:21 +00:00
sed -i -e 's/^module(load=\"imklog\")/#module(load=\"imklog\")/' /etc/rsyslog.conf && \
2021-01-18 19:51:56 +00:00
# prevent email when /sbin/init or init system is not existing
2020-04-22 22:39:56 +00:00
sed -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 21:38:52 +00:00
2021-01-16 09:16:05 +00:00
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# – – – Supervisord & Start – – – – – – – – – – – – – – – – – – – – – – –
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
2016-02-08 22:47:42 +00:00
2017-09-10 13:26:21 +00:00
COPY target/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY target/supervisor/conf.d/* /etc/supervisor/conf.d/
2016-01-23 22:51:09 +00:00
2019-08-13 09:41:38 +00:00
WORKDIR /
2017-09-07 16:08:25 +00:00
EXPOSE 25 587 143 465 993 110 995 4190
2016-09-29 20:52:05 +00:00
2021-01-16 18:35:42 +00:00
ENTRYPOINT [ "/usr/bin/dumb-init" , "--" ]
2018-11-04 19:23:50 +00:00
CMD [ "supervisord" , "-c" , "/etc/supervisor/supervisord.conf" ]