3

I have an issue with a Postfix instance in a Docker container. I'm using supervisord to make sure the services run in the background. However, if I build the image, start it up for the first time and try to send a mail, Postfix complains that it can't 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 find out if its an DNS issue, but I can resolve the MX straight:

$ 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.

Then I proceeded to restart the Postfix with service postfix restart and was pretty startled that the MX issue is gone. I reproduced the issue more than three times and its always the same. I have to issue service postfix restart to make Postfix work fully functional.

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

Thanks in advance!

frdmn
  • 359
  • 1
  • 2
  • 11
  • I'm having the same issue. Still working on it. I found if I run bind in the container and modify /etc/resolv.conf to use 127.0.0.1 then postfix DNS resolution works. Not thrilled with that solution, as I'm not sure how to keep that resolv.conf setting pinned. Still trying to figure out the root cause. – James Cooper Nov 26 '14 at 16:32
  • @JamesCooper me too. Couldn't get it to work, even with custom DNS (Google) passed to Docker. This is going to driving me nuts :P – frdmn Dec 18 '14 at 08:07
  • Same issue, also with Exim. I installed `host` and curiously it answers A for -t MX or -t ANY which is what I assume Postfix and Exim are resolving. – jkoreska Jan 05 '15 at 20:47

2 Answers2

4

I ran into the same issue when I tried to install postfix on a phusion/baseimage, which replaces ubuntus init.d system with runit. If you issue "service postfix restart", this nevertheless runs the postfix script in /etc/init.d, which in turn does A LOT of things I don't understand. One of them 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. Thus, 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
rednil
  • 41
  • 3
0

If you're using a VirtualBox VM you've probably run into this bug: https://www.virtualbox.org/ticket/11540

Edit:

To elaborate, I was having the exact issue, also with Exim in Docker. I installed an alternate DNS tool host in my Docker containers and it answered A records when running it with -t MX or even -t ANY. That led me to believe DNS was broken which led me to that VirtualBox bug.

It's not Postfix or Docker, it's a bug in DNS resolution on a VirtualBox VM with a default resolv.conf. Running the same software in another environment does not have this issue.

jkoreska
  • 7,210
  • 2
  • 18
  • 21
  • This was posted as an answer, but it does not attempt to answer the question. It should possibly be an edit, a comment, another question, or deleted altogether. ***Link-only answers are not acceptable.*** – AStopher Jan 05 '15 at 21:05
  • Fair enough. I had the exact issue and that link answers the crux of the question. I will elaborate. – jkoreska Jan 05 '15 at 21:10
  • @jkoreska thank you for your reply. Unfortunately I dont run it in a VM. – frdmn Jan 09 '15 at 09:29