Remove these lines:
RUN touch /dev/xconsole && chgrp syslog /dev/xconsole && chmod 664 /dev/xconsole
RUN service rsyslog restart
And update CMD
to start rsyslog at first:
CMD service rsyslog start && service postfix start && tail -f /var/log/mail.log
Because RUN
executes command during the image build whereas CMD
executes command in the running container and you need to run rsyslogd in a running container.
Result Dockerfile can look like this:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y libsasl2-modules postfix rsyslog; \
rm -rf /var/lib/apt/lists/*
RUN echo "[smtp.gmail.com]:587 email@gmail.com:password" > /etc/postfix/sasl_passwd; \
postmap /etc/postfix/sasl_passwd; \
sed -i '/relayhost*/c\relayhost = [smtp.gmail.com]:587' /etc/postfix/main.cf; \
sed -i '/smtp_sasl_auth_enable*/c\smtp_sasl_auth_enable = yes' /etc/postfix/main.cf; \
sed -i '/smtp_sasl_security_options*/c\smtp_sasl_security_options = noanonymous' /etc/postfix/main.cf; \
sed -i '/smtp_sasl_password_maps*/c\smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd' /etc/postfix/main.cf; \
sed -i '/smtp_tls_security_level*/c\smtp_tls_security_level = encrypt' /etc/postfix/main.cf; \
sed -i '/smtp_tls_CAfile*/c\smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt' /etc/postfix/main.cf
EXPOSE 587
CMD service rsyslog start && service postfix start && tail -f /var/log/mail.log
Build it: docker build -t postfix -f Dockerfile.postfix .
And when you run it: docker run -it --rm --name postfix postfix
... then you have mail log in console:
* Starting enhanced syslogd rsyslogd [ OK ]
* Starting Postfix Mail Transport Agent postfix postfix: Postfix is running with backwards-compatible default settings
postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details
postfix: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
[ OK ]
Sep 26 20:11:01 6009a2e3d206 postfix[111]: Postfix is running with backwards-compatible default settings
Sep 26 20:11:01 6009a2e3d206 postfix[111]: See http://www.postfix.org/COMPATIBILITY_README.html for details
Sep 26 20:11:01 6009a2e3d206 postfix[111]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Sep 26 20:11:01 6009a2e3d206 postfix/master[156]: daemon started -- version 3.1.0, configuration /etc/postfix
Sep 26 20:11:01 6009a2e3d206 postfix/pickup[159]: error: open file /etc/mailname: No such file or directory
Sep 26 20:11:01 6009a2e3d206 postfix/qmgr[160]: error: open file /etc/mailname: No such file or directory
You can also check the mail log using exec command: docker exec postfix cat /var/log/mail.log
. This can be helpful when running container as a daemon (-d
flag).
Regarding the rsyslogd-2039: Could not open output pipe
error - you can ignore it.
But if you don't want to ignore it you can update your CMD
and have it like this:
CMD touch /dev/xconsole && chgrp syslog /dev/xconsole && chmod 664 /dev/xconsole && service rsyslog start && service postfix start && tail -f /var/log/mail.log