From 4227d0475388732bd6094573289d4a47f97844bb Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sat, 28 Mar 2015 15:59:15 +0100 Subject: [PATCH] First commit. Need to add README and default configurations. --- Dockerfile | 33 ++++++++++++++++++++++++++++ start-mailserver.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 Dockerfile create mode 100644 start-mailserver.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..51f64e90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:14.04 +MAINTAINER Thomas VIAL + +# Packages +RUN apt-get update -q +RUN apt-get -y upgrade +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install postfix sasl2-bin courier-imap courier-authdaemon supervisor libfam0 fam amavisd-new spamassassin clamav-daemon libnet-dns-perl libmail-spf-perl pyzor razor arj bzip2 cabextract cpio file gzip nomarch pax unzip zip zoo +RUN apt-get autoclean + +# Configures Saslauthd +RUN rm -rf /var/run/saslauthd && ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd +RUN adduser postfix sasl +RUN echo 'NAME="saslauthd"\nSTART=yes\nMECHANISMS="sasldb"\nTHREADS=0\nPWDIR=/var/spool/postfix/var/run/saslauthd\nPIDFILE="${PWDIR}/saslauthd.pid"\nOPTIONS="-n 0 -r -m /var/spool/postfix/var/run/saslauthd"' > /etc/default/saslauthd + +# Enables Spamassassin and CRON updates +RUN sed -i -r 's/^(CRON|ENABLED)=0/\1=1/g' /etc/default/spamassassin + +# Enables Amavis +RUN sed -i -r 's/#(@| \\%)bypass/\1bypass/g' /etc/amavis/conf.d/15-content_filter_mode +RUN adduser clamav amavis +RUN adduser amavis clamav +RUN echo "/dev/shm /var/lib/amavis tmpfs defaults,noexec,nodev,nosuid,size=150m,mode=750,uid=$(id -u amavis),gid=$(id -g clamav) 0 0" >> /etc/fstab + +# Enables Clamav +RUN mkdir -p /var/log/clamav && chown -R clamav:root /var/log/clamav +RUN (crontab -l ; echo "0 1 * * * /usr/bin/freshclam --quiet") | sort - | uniq - | crontab - +RUN freshclam + +# Start-mailserver script +ADD start-mailserver.sh /usr/local/bin/start-mailserver.sh +RUN chmod +x /usr/local/bin/start-mailserver.sh +CMD /usr/local/bin/start-mailserver.sh + diff --git a/start-mailserver.sh b/start-mailserver.sh new file mode 100644 index 00000000..b247332f --- /dev/null +++ b/start-mailserver.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +echo "Regenerating 'vmailbox' for given users" + +echo "docker_mail_users => $docker_mail_users" + +echo "# WARNING: this file is auto-generated. Do not modify locally" > /etc/postfix/vmailbox +while IFS=$'|' read -r login pass +do + # Setting variables for better readability + user=$(echo ${login} | cut -d @ -f1) + domain=$(echo ${login} | cut -d @ -f2) + + # Let's go! + echo "user '${user}' for domain '${domain}' with password '${pass}'" + echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox + userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user} + echo "${pass}" | userdbpw -md5 | userdb ${login} set systempw + echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login} + mkdir -p /var/mail/ifusio.com + maildirmake /var/mail/${domain}/${user} + +done < /etc/postfix/docker-mail-users +makeuserdb + +echo "Postmap configurations" +postmap /etc/postfix/vmailbox +postmap /etc/postfix/virtual + +echo "Fixing permissions" +chown -R 5000:5000 /var/mail + +echo "Creating /etc/mailname" +echo $docker_mail_domain > /etc/mailname + +# echo "Mouting /var/lib/amavis as tmpfs" +# mount /var/lib/amavis + +echo "Starting daemons" +/etc/init.d/fam start +/etc/init.d/saslauthd start +/etc/init.d/courier-authdaemon start +/etc/init.d/courier-imap start +/etc/init.d/spamassassin start +/etc/init.d/clamav-daemon start +/etc/init.d/amavis start +/etc/init.d/postfix start + +echo "Listing SASL users" +sasldblistusers2 + +echo "Starting supervisord" +tail -f /var/log/mail.log \ No newline at end of file