4

Is there any way to run postfix in foreground?

I want to run postfix as PID 1 in docker. and i dont want to use any bash shell, supervisorD, or any wrapper to start it. I just want to know if there is any way to start it in foreground so i can check its logs from "docker logs 'container-name'"

When i manually run "postfix start" it runs and then starts in background. any way to keep it in foreground?

Thanks

3

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
12

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!

  • Please note that if Postfix is launched in chroot environment (which is default in many distros) with postfix start-fg, you will have the /var/spool/postfix/etc dir empty, postfix will not know your localtime, hosts, resolv.conf, you will not be able to deliver a single message. See the difference when you run regular service postfix start. – sekrett Sep 26 '18 at 15:22
  • 2
    @sekrett That is correct, however, while inside a Docker container as per the OP's question, I would advise not to use chroot (it would be redundant). – Isaac Uribe Jan 4 '19 at 14:00
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.