Dockerize postfix

This commit is contained in:
Disassembler 2018-01-15 20:05:33 +01:00
parent bcb40b3ac1
commit edb2b6cd8c
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
8 changed files with 69 additions and 10 deletions

View File

@ -4,11 +4,10 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/basic
# Install packages
apk --no-cache add --virtual .useful git file htop libressl openssh-server openssh-sftp-server
apk --no-cache add docker gettext kbd-misc postfix python2 nginx
apk --no-cache add docker gettext kbd-misc python2 nginx
# Copy profile files and settings
mkdir /root/.ssh
mkdir -p /root/.config/htop
mkdir -p /root/.config/htop /root/.ssh
cp ${SOURCE_DIR}/root/.profile /root/.profile
cp ${SOURCE_DIR}/root/.ssh/authorized_keys /root/.ssh/authorized_keys
cp ${SOURCE_DIR}/root/.config/htop/htoprc /root/.config/htop/htoprc
@ -27,9 +26,6 @@ cp ${SOURCE_DIR}/etc/issue.template /etc/issue.template
cp ${SOURCE_DIR}/sbin/issue-gen /sbin/issue-gen
>/etc/motd
# Configure Postfix
cp ${SOURCE_DIR}/etc/postfix/main.cf /etc/postfix/main.cf
# Create a self-signed certificate
mkdir /etc/ssl/private
openssl req -x509 -new -out /etc/ssl/certs/services.pem -keyout /etc/ssl/private/services.key -nodes -days 3654 -subj "/C=CZ/CN=$(hostname -f)"
@ -45,7 +41,7 @@ cp ${SOURCE_DIR}/usr/local/bin/portal-app-manager /usr/local/bin/portal-app-mana
cp -r ${SOURCE_DIR}/srv/portal /srv/portal
# Configure services
for SERVICE in crond docker nginx postfix sshd; do
for SERVICE in crond docker nginx sshd; do
rc-update add ${SERVICE} boot
service ${SERVICE} start
done

18
postfix.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/postfix
# Build Docker container
docker build -t postfix ${SOURCE_DIR}
# Copy existing config files into persistent storage
mkdir -p /srv/postfix/conf /srv/postfix/data
chown -R 587:587 /srv/postfix/data
docker run --rm -v /srv/postfix/conf:/mnt/conf postfix cp -rp /etc/postfix/. /mnt/conf
# Configure postfix
cp ${SOURCE_DIR}/srv/postfix/conf/main.cf /srv/postfix/conf/main.cf
# Configure postfix service
cp ${SOURCE_DIR}/etc/init.d/postfix /etc/init.d/postfix
rc-update add postfix boot
service postfix start

16
postfix/Dockerfile Normal file
View File

@ -0,0 +1,16 @@
FROM alpine:3.7
MAINTAINER Disassembler <disassembler@dasm.cz>
RUN \
# Create OS user (which will be picked up later by apk add)
addgroup -S -g 587 postfix \
&& adduser -S -u 587 -h /var/spool/postfix -s /bin/false -g postfix -G postfix postfix \
# Install Postfix
&& apk --no-cache add ca-certificates postfix s6
COPY docker/ /
VOLUME ["/var/spool/postfix"]
EXPOSE 587
CMD ["s6-svscan", "/etc/services.d"]

View File

@ -0,0 +1,3 @@
#!/bin/sh
/bin/true

View File

@ -0,0 +1,7 @@
#!/bin/sh
/usr/sbin/postfix -c /etc/postfix start
while kill -0 $(cat /var/spool/postfix/pid/master.pid) 2>/dev/null; do
sleep 1
done

View File

@ -0,0 +1,3 @@
#!/bin/execlineb -P
/sbin/syslogd -n -S -O -

16
postfix/etc/init.d/postfix Executable file
View File

@ -0,0 +1,16 @@
#!/sbin/openrc-run
description="Postfix docker container"
depend() {
need docker net
use dns logger netmount
}
start() {
/usr/bin/docker run -d --rm --name postfix -v /srv/postfix/conf:/etc/postfix -v /srv/postfix/data:/var/spool/postfix postfix
}
stop() {
/usr/bin/docker stop postfix
}

View File

@ -1,8 +1,8 @@
append_dot_mydomain = no
biff = no
compatibility_level = 2
inet_interfaces = loopback-only
inet_protocols = ipv4
mynetworks = 127.0.0.0/8 172.17.0.0/24
mynetworks = 0.0.0.0/0
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_use_tls=yes
smtp_use_tls = yes
smtputf8_enable = no