Search code examples
dockernagiospostfix-mta

Docker - Changes to postfix's main.cf file are overriden on container start


I am trying to setup a dockerized Nagios. For that, I am using the already working image from jasonrivers: Dockerfile

Now, I need to slightly adjust the postfix, that is already installed in the image. I need to setup a relayhost so that e-mails that are sent from nagios are forwarded to my Mail-Server. Which should be as simple as setting the "relayhost" property in /etc/postfix/main.cf. However, no matter how I adjust this value in my Dockerfile (I tried doing it with both sed and a COPY), when I inspect the /etc/postfix/main.cf file after starting the container the relayhost value was overridden to an empty value.

At first I thought that this has to do something with docker itself, I thought that somehow my steps in the Dockerfile that adjust this file did not end up affecting the final image. However, when I override main.cf with gibberish (like setting it's content to just "foo") then upon running the image, postfix throws some errors about it.

To put the words into code, consider this Dockerfile:

FROM jasonrivers/nagios:latest
RUN echo "relayhost = www.abc.com" > /etc/postfix/main.cf

Building this and then running the resulting image will result in a /etc/postfix/main.cf file with contents

relayhost = 

I have tried using google to figure out how postfix works and why it does that, but the only suggestion I found was that something is configured in "master.cf", which it is not (you can download the image yourself and test all this yourself).


Solution

  • The JasonRivers/Docker-Nagios repo for the image has a feature in the postfix startup script to modify that setting overlay/etc/sv/postfix/run:

    sed -i "s/relayhost =.*/relayhost = ${MAIL_RELAY_HOST}/" /etc/postfix/main.cf
    

    Set the MAIL_RELAY_HOST environment variable to your host.

    ENV MAIL_RELAY_HOST=www.abc.com