Is there any way to run Postfix in foreground?
Postfix needs a syslog daemon for logging. For a concise example of a Dockerfile
running Postfix see jessfraz/dockerfiles/postfix.
This runs rsyslog
in the container and starts Postfix parallel to that like this:
exec /usr/lib/postfix/master -c /etc/postfix -d 2>&1
tail -F /var/log/mail.log
Starting with Postfix version 3.3, you can also use postfix start-fg
, which according to the documentation:
Like start, but keep the master(8) daemon running in the fore-ground
It makes things much easier!
Since Postfix 3.3, docker is natively supported. Simply build and run this Dockerfile :
FROM alpine:3
RUN apk add --no-cache postfix postfix-pcre
RUN echo "maillog_file = /dev/stdout" >> /etc/postfix/main.cf
CMD ["/usr/sbin/postfix","start-fg"]
If I understood your question you want to run postfix in the foregroud, so it gets its logs sent to the stdout and you can display them using docker logs.
You cannot run Postfix in a way that its logs are sent to the stdout. From the official docs "Postfix daemon processes run in the background, and log problems and normal activity to the syslog daemon.", so syslogd is used by Postfix to manage its logs, and that's a requirement you cannot avoid.
As Docker will "ignore" log output that is not sent to stdout/stderr you should have to look for alternatives.
This conversation gives you more information about postfix and syslogd requirement and possible strategies in Docker. Basically it will try to send the syslog output to your host's syslog log files, but you won't be able to use docker logs to read them.
This old container in Docker Hub tries to do what you want, at least explains the same issue that you want to solve.
Finally, I found this article helpful (referenced in the nabble discussion) to understand the problem of getting the syslogd information out of a container.