2019-12-31 15:34:21 +00:00
|
|
|
FROM debian:buster-slim
|
2019-10-23 09:22:23 +00:00
|
|
|
|
|
|
|
ARG VCS_REF
|
|
|
|
ARG VCS_VERSION
|
|
|
|
|
|
|
|
LABEL maintainer="Thomas VIAL" \
|
|
|
|
org.label-schema.name="docker-mailserver" \
|
|
|
|
org.label-schema.description="A fullstack but simple mailserver (smtp, imap, antispam, antivirus, ssl...)" \
|
|
|
|
org.label-schema.url="https://github.com/tomav/docker-mailserver" \
|
|
|
|
org.label-schema.vcs-ref=$VCS_REF \
|
|
|
|
org.label-schema.vcs-url="https://github.com/tomav/docker-mailserver" \
|
|
|
|
org.label-schema.version=$VCS_VERSION \
|
|
|
|
org.label-schema.schema-version="1.0"
|
2015-03-28 14:59:15 +00:00
|
|
|
|
2019-07-24 12:48:59 +00:00
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
2017-03-14 16:21:17 +00:00
|
|
|
ENV VIRUSMAILS_DELETE_DELAY=7
|
|
|
|
ENV ONE_DIR=0
|
2017-08-07 15:39:40 +00:00
|
|
|
ENV ENABLE_POSTGREY=0
|
2017-10-04 20:10:18 +00:00
|
|
|
ENV FETCHMAIL_POLL=300
|
2017-08-07 15:39:40 +00:00
|
|
|
ENV POSTGREY_DELAY=300
|
|
|
|
ENV POSTGREY_MAX_AGE=35
|
2018-11-01 18:32:36 +00:00
|
|
|
ENV POSTGREY_AUTO_WHITELIST_CLIENTS=5
|
2017-08-07 15:39:40 +00:00
|
|
|
ENV POSTGREY_TEXT="Delayed by postgrey"
|
|
|
|
|
|
|
|
ENV SASLAUTHD_MECHANISMS=pam
|
|
|
|
ENV SASLAUTHD_MECH_OPTIONS=""
|
2017-03-14 14:22:19 +00:00
|
|
|
|
2019-08-13 09:41:38 +00:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
|
|
|
2015-03-28 14:59:15 +00:00
|
|
|
# Packages
|
2020-04-12 01:18:08 +00:00
|
|
|
# hadolint ignore=DL3015,DL3005
|
2019-12-31 15:34:21 +00:00
|
|
|
RUN \
|
2019-08-13 09:41:38 +00:00
|
|
|
apt-get update -q --fix-missing && \
|
2020-04-10 10:47:58 +00:00
|
|
|
apt-get -y upgrade && \
|
2017-07-23 17:38:34 +00:00
|
|
|
apt-get -y install postfix && \
|
2016-08-30 07:59:46 +00:00
|
|
|
apt-get -y install --no-install-recommends \
|
2020-01-06 12:10:46 +00:00
|
|
|
altermime \
|
2016-08-30 07:59:46 +00:00
|
|
|
amavisd-new \
|
2019-08-30 11:43:11 +00:00
|
|
|
apt-transport-https \
|
2016-08-30 07:59:46 +00:00
|
|
|
arj \
|
2017-08-07 15:37:16 +00:00
|
|
|
binutils \
|
2016-08-30 07:59:46 +00:00
|
|
|
bzip2 \
|
2017-04-27 15:59:28 +00:00
|
|
|
ca-certificates \
|
2017-08-07 15:37:16 +00:00
|
|
|
cabextract \
|
2016-08-30 07:59:46 +00:00
|
|
|
clamav \
|
|
|
|
clamav-daemon \
|
2017-08-07 15:37:16 +00:00
|
|
|
cpio \
|
2016-08-30 07:59:46 +00:00
|
|
|
curl \
|
|
|
|
ed \
|
|
|
|
fail2ban \
|
|
|
|
fetchmail \
|
|
|
|
file \
|
|
|
|
gamin \
|
|
|
|
gzip \
|
2017-12-31 11:33:48 +00:00
|
|
|
gnupg \
|
|
|
|
iproute2 \
|
2016-08-30 07:59:46 +00:00
|
|
|
iptables \
|
2017-04-27 15:59:28 +00:00
|
|
|
locales \
|
2019-09-15 13:40:05 +00:00
|
|
|
logwatch \
|
2020-01-06 12:10:46 +00:00
|
|
|
lhasa \
|
2019-09-15 13:40:05 +00:00
|
|
|
libdate-manip-perl \
|
2017-08-07 15:37:16 +00:00
|
|
|
liblz4-tool \
|
2016-08-30 07:59:46 +00:00
|
|
|
libmail-spf-perl \
|
|
|
|
libnet-dns-perl \
|
|
|
|
libsasl2-modules \
|
2017-08-07 15:37:16 +00:00
|
|
|
lrzip \
|
|
|
|
lzop \
|
2017-04-27 15:59:28 +00:00
|
|
|
netcat-openbsd \
|
2017-08-07 15:37:16 +00:00
|
|
|
nomarch \
|
2016-08-30 07:59:46 +00:00
|
|
|
opendkim \
|
|
|
|
opendkim-tools \
|
|
|
|
opendmarc \
|
2017-08-07 15:37:16 +00:00
|
|
|
pax \
|
2018-03-18 18:52:28 +00:00
|
|
|
pflogsumm \
|
2017-08-07 15:37:16 +00:00
|
|
|
p7zip-full \
|
2016-10-30 13:11:36 +00:00
|
|
|
postfix-ldap \
|
2017-08-09 21:19:00 +00:00
|
|
|
postfix-pcre \
|
2017-03-14 16:21:17 +00:00
|
|
|
postfix-policyd-spf-python \
|
2018-02-06 07:11:57 +00:00
|
|
|
postsrsd \
|
2016-08-30 07:59:46 +00:00
|
|
|
pyzor \
|
|
|
|
razor \
|
2017-08-07 15:37:16 +00:00
|
|
|
rpm2cpio \
|
2016-08-30 07:59:46 +00:00
|
|
|
rsyslog \
|
2016-10-30 13:11:36 +00:00
|
|
|
sasl2-bin \
|
2016-08-30 07:59:46 +00:00
|
|
|
spamassassin \
|
2017-08-07 15:39:40 +00:00
|
|
|
supervisor \
|
2017-02-06 09:21:18 +00:00
|
|
|
postgrey \
|
2017-08-07 15:37:16 +00:00
|
|
|
unrar-free \
|
2016-08-30 07:59:46 +00:00
|
|
|
unzip \
|
2019-08-01 11:37:02 +00:00
|
|
|
whois \
|
2017-08-07 15:37:16 +00:00
|
|
|
xz-utils \
|
2019-08-31 07:15:42 +00:00
|
|
|
# use Dovecot community repo to react faster on security updates
|
2019-12-31 15:34:21 +00:00
|
|
|
#curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import && \
|
|
|
|
#gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg && \
|
|
|
|
#echo "deb https://repo.dovecot.org/ce-2.3-latest/debian/stretch stretch main" > /etc/apt/sources.list.d/dovecot-community.list && \
|
|
|
|
#apt-get update -q --fix-missing && \
|
|
|
|
#apt-get -y install --no-install-recommends \
|
2018-02-04 20:27:47 +00:00
|
|
|
dovecot-core \
|
|
|
|
dovecot-imapd \
|
|
|
|
dovecot-ldap \
|
|
|
|
dovecot-lmtpd \
|
|
|
|
dovecot-managesieved \
|
|
|
|
dovecot-pop3d \
|
|
|
|
dovecot-sieve \
|
2019-11-10 09:14:27 +00:00
|
|
|
dovecot-solr \
|
2018-02-04 20:27:47 +00:00
|
|
|
&& \
|
2017-07-23 17:38:34 +00:00
|
|
|
apt-get autoclean && \
|
|
|
|
rm -rf /var/lib/apt/lists/* && \
|
|
|
|
rm -rf /usr/share/locale/* && \
|
|
|
|
rm -rf /usr/share/man/* && \
|
|
|
|
rm -rf /usr/share/doc/* && \
|
|
|
|
touch /var/log/auth.log && \
|
2017-07-23 19:03:06 +00:00
|
|
|
update-locale && \
|
2018-03-10 12:41:20 +00:00
|
|
|
rm -f /etc/cron.weekly/fstrim && \
|
2019-09-15 13:40:05 +00:00
|
|
|
rm -f /etc/postsrsd.secret && \
|
|
|
|
rm -f /etc/cron.daily/00logwatch
|
2015-03-28 14:59:15 +00:00
|
|
|
|
2019-07-29 09:15:49 +00:00
|
|
|
RUN 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 && \
|
|
|
|
sed -i 's/AllowSupplementaryGroups false/AllowSupplementaryGroups 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
|
|
|
|
2016-04-07 12:20:51 +00:00
|
|
|
# Configures Dovecot
|
2017-07-23 17:38:34 +00:00
|
|
|
COPY target/dovecot/auth-passwdfile.inc target/dovecot/??-*.conf /etc/dovecot/conf.d/
|
2019-08-13 09:41:38 +00:00
|
|
|
WORKDIR /usr/share/dovecot
|
|
|
|
# hadolint ignore=SC2016,SC2086
|
2017-07-23 17:38:34 +00:00
|
|
|
RUN sed -i -e 's/include_try \/usr\/share\/dovecot\/protocols\.d/include_try \/etc\/dovecot\/protocols\.d/g' /etc/dovecot/dovecot.conf && \
|
|
|
|
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 && \
|
2019-08-31 07:15:42 +00:00
|
|
|
# Adapt mkcert for Dovecot community repo
|
|
|
|
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 && \
|
|
|
|
# create directory for certificates created by mkcert
|
2018-02-04 20:27:47 +00:00
|
|
|
mkdir /etc/dovecot/ssl && \
|
|
|
|
chmod 755 /etc/dovecot/ssl && \
|
2019-08-13 09:41:38 +00:00
|
|
|
./mkcert.sh && \
|
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
|
|
|
|
2016-11-13 10:39:45 +00:00
|
|
|
# Configures LDAP
|
|
|
|
COPY target/dovecot/dovecot-ldap.conf.ext /etc/dovecot
|
2017-08-19 08:32:00 +00:00
|
|
|
COPY target/postfix/ldap-users.cf target/postfix/ldap-groups.cf target/postfix/ldap-aliases.cf target/postfix/ldap-domains.cf /etc/postfix/
|
2016-11-13 10:39:45 +00:00
|
|
|
|
2017-08-19 08:49:02 +00:00
|
|
|
# Enables Spamassassin CRON updates and update hook for supervisor
|
2019-08-13 09:41:38 +00:00
|
|
|
# hadolint ignore=SC2016
|
2017-08-19 08:49:02 +00:00
|
|
|
RUN sed -i -r 's/^(CRON)=0/\1=1/g' /etc/default/spamassassin && \
|
|
|
|
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
|
|
|
|
2017-04-18 12:18:42 +00:00
|
|
|
# Enables Postgrey
|
2017-02-06 09:21:18 +00:00
|
|
|
COPY target/postgrey/postgrey /etc/default/postgrey
|
|
|
|
COPY target/postgrey/postgrey.init /etc/init.d/postgrey
|
2017-07-23 17:38:34 +00:00
|
|
|
RUN chmod 755 /etc/init.d/postgrey && \
|
|
|
|
mkdir /var/run/postgrey && \
|
|
|
|
chown postgrey:postgrey /var/run/postgrey
|
2017-02-06 09:21:18 +00:00
|
|
|
|
2018-02-06 07:11:57 +00:00
|
|
|
# Copy PostSRSd Config
|
|
|
|
COPY target/postsrsd/postsrsd /etc/default/postsrsd
|
|
|
|
|
2015-03-28 14:59:15 +00:00
|
|
|
# Enables Amavis
|
2017-08-09 21:19:00 +00:00
|
|
|
COPY target/amavis/conf.d/* /etc/amavis/conf.d/
|
2017-07-23 17:38:34 +00:00
|
|
|
RUN sed -i -r 's/#(@| \\%)bypass/\1bypass/g' /etc/amavis/conf.d/15-content_filter_mode && \
|
|
|
|
adduser clamav amavis && \
|
|
|
|
adduser amavis clamav && \
|
2017-12-31 11:33:48 +00:00
|
|
|
# no syslog user in debian compared to ubuntu
|
|
|
|
adduser --system syslog && \
|
2019-08-13 09:41:38 +00:00
|
|
|
useradd -u 5000 -d /home/docker -s /bin/bash -p "$(echo docker | openssl passwd -1 -stdin)" docker && \
|
|
|
|
echo "0 4 * * * /usr/local/bin/virus-wiper" | crontab -
|
2015-03-28 14:59:15 +00:00
|
|
|
|
2016-04-17 20:59:35 +00:00
|
|
|
# Configure Fail2ban
|
2016-09-04 18:37:16 +00:00
|
|
|
COPY target/fail2ban/jail.conf /etc/fail2ban/jail.conf
|
|
|
|
COPY target/fail2ban/filter.d/dovecot.conf /etc/fail2ban/filter.d/dovecot.conf
|
2020-01-06 12:10:46 +00:00
|
|
|
COPY target/fail2ban/filter.d/postfix-sasl.conf /etc/fail2ban/filter.d/postfix-sasl.conf
|
|
|
|
RUN mkdir /var/run/fail2ban
|
2016-04-17 20:59:35 +00:00
|
|
|
|
2016-04-21 16:04:33 +00:00
|
|
|
# Enables Pyzor and Razor
|
2019-08-13 09:41:38 +00:00
|
|
|
RUN su - amavis -c "razor-admin -create && \
|
|
|
|
razor-admin -register"
|
2016-04-21 16:04:33 +00:00
|
|
|
|
2016-01-20 15:41:34 +00:00
|
|
|
# Configure DKIM (opendkim)
|
|
|
|
# DKIM config files
|
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-01-26 17:26:50 +00:00
|
|
|
# Configure DMARC (opendmarc)
|
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
|
|
|
|
2016-08-21 20:13:13 +00:00
|
|
|
# Configure fetchmail
|
2016-09-04 18:37:16 +00:00
|
|
|
COPY target/fetchmail/fetchmailrc /etc/fetchmailrc_general
|
2016-08-21 20:13:13 +00:00
|
|
|
RUN sed -i 's/START_DAEMON=no/START_DAEMON=yes/g' /etc/default/fetchmail
|
2017-08-07 15:39:40 +00:00
|
|
|
RUN mkdir /var/run/fetchmail && chown fetchmail /var/run/fetchmail
|
2016-08-21 20:13:13 +00:00
|
|
|
|
2015-03-31 15:27:54 +00:00
|
|
|
# Configures Postfix
|
2016-09-04 18:37:16 +00:00
|
|
|
COPY target/postfix/main.cf target/postfix/master.cf /etc/postfix/
|
2018-11-01 18:32:36 +00:00
|
|
|
COPY target/postfix/header_checks.pcre target/postfix/sender_header_filter.pcre target/postfix/sender_login_maps.pcre /etc/postfix/maps/
|
2019-08-09 20:13:50 +00:00
|
|
|
RUN echo "" > /etc/aliases
|
2015-03-31 15:27:54 +00:00
|
|
|
|
2016-04-18 21:38:52 +00:00
|
|
|
# Configuring Logs
|
2016-04-24 11:46:48 +00:00
|
|
|
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 && \
|
|
|
|
sed -i -r 's|/var/log/clamav|/var/log/mail|g' /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 && \
|
2017-09-12 17:33:52 +00:00
|
|
|
# prevent syslog logrotate warnings \
|
|
|
|
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 && \
|
|
|
|
# prevent email when /sbin/init or init system is not existing \
|
|
|
|
sed -i -e 's/invoke-rc.d rsyslog rotate > \/dev\/null/invoke-rc.d rsyslog --quiet rotate > \/dev\/null/g' /etc/logrotate.d/rsyslog
|
2016-04-18 21:38:52 +00:00
|
|
|
|
2016-02-08 22:47:42 +00:00
|
|
|
# Get LetsEncrypt signed certificate
|
2017-01-11 09:52:39 +00:00
|
|
|
RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > /etc/ssl/certs/lets-encrypt-x3-cross-signed.pem
|
2016-02-08 22:47:42 +00:00
|
|
|
|
2016-09-04 18:37:16 +00:00
|
|
|
COPY ./target/bin /usr/local/bin
|
2015-03-28 14:59:15 +00:00
|
|
|
# Start-mailserver script
|
2019-08-07 00:24:56 +00:00
|
|
|
COPY ./target/helper_functions.sh ./target/check-for-changes.sh ./target/start-mailserver.sh ./target/fail2ban-wrapper.sh ./target/postfix-wrapper.sh ./target/postsrsd-wrapper.sh ./target/docker-configomat/configomat.sh /usr/local/bin/
|
2016-04-24 11:46:48 +00:00
|
|
|
RUN chmod +x /usr/local/bin/*
|
2016-01-08 16:52:06 +00:00
|
|
|
|
2017-08-07 15:39:40 +00:00
|
|
|
# Configure supervisor
|
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 /
|
|
|
|
|
2020-01-06 12:10:46 +00:00
|
|
|
# Switch iptables and ip6tables to legacy for fail2ban
|
|
|
|
RUN update-alternatives --set iptables /usr/sbin/iptables-legacy \
|
|
|
|
&& update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-11-04 19:23:50 +00:00
|
|
|
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
|