Postfix in Docker container cannot resolve MX unless it restarts once

I have a problem with a Postfix instance in a Docker container. I am using supervisord

to make sure services are running in the background. However, if I create an image, run it the first time and try to send mail, Postfix complains that it cannot resolve the MX record for the given address ( status=deferred (Host or domain name not found. Name service error for name=domain.tld type=MX: Host not found, try again)

).

Now I installed dig

to see if there is a DNS issue, but I can resolve MX directly:

$ dig mx domain.tld +short
90 aspmx2.googlemail.com.
90 aspmx3.googlemail.com.
10 aspmx.l.google.com.
50 alt1.aspmx.l.google.com.
50 alt2.aspmx.l.google.com.

      

I then proceeded to restart Postfix with service postfix restart

and was very surprised that the MX issue was gone. I have reproduced this problem more than three times and its always the same. I have to post service postfix restart

to make Postfix work fully functional.

Can someone explain to me why or even better: how to fix this?

Thanks in advance!

+3


source to share


2 answers


I ran into the same problem when I tried to install postfix on phusion / baseimage which replaces the ubuntus init.d system with runit. If you issue "restart postfix service" it still runs the postfix script in /etc/init.d, which in turn does a lot of things that I don't understand. One is to copy a bunch of files from / etc to / var / spool / postfix / etc, including resolv.conf. Copying this file fixed this issue for me. So in your run script add (taken from /etc/init.d/postfix)



FILES="localtime services resolv.conf hosts nsswitch.conf nss_mdns.config"
for file in $FILES; do
    cp /etc/${file} /var/spool/postfix/etc/${file}
    chmod a+rX /var/spool/postfix/etc/${file}
done

      

+2


source


If you are using the VirtualBox virtual machine, you probably ran into this error: https://www.virtualbox.org/ticket/11540

Edit:



To clarify, I had the exact problem, also with Exim in Docker. I have installed an alternative DNS tool host

in my Docker containers and responded to A

startup entries with -t MX

or even -t ANY

. This led me to have the DNS broken, which led me to the VirtualBox error.

This is not Postfix or Docker, this is a bug in DNS resolution in the default VM resolv.conf

. Running the same software in a different environment does not have this problem.

0


source







All Articles