DNS lookups fail
regnete opened this issue · 12 comments
docker-compose yml
services:
smtp:
image: juanluisbaptiste/postfix
environment:
SERVER_HOSTNAME: "xxx"
SMTP_SERVER: 'smtp.mydomain.intranet'
SMTP_PORT: '587'
SMTP_USERNAME: 'someuser'
SMTP_PASSWORD: "secret"
extra_hosts:
- "smtp.mydomain.intranet:192.168.5.1"
Describe the issue
postfix cannot resolve the host smtp.mydomain.intranet
I guess this happens due to the issue decribed here: https://serverfault.com/a/1004330
Expected behavior
postfix resolves the host smtp.mydomain.intranet to 192.168.5.1
@regnete , for me resolution is working fine. Using your example compose file, entering a container and doing a ping to smtp.mydomain.intranet resolves correctly:
# ping smtp.mydomain.intranet
PING smtp.mydomain.intranet (192.168.5.1): 56 data bytes
Thx for the quick answer. PING is not the problem. Postfix cannot send emails to the given host. It fails with a DNS resolution error.
Can you please post the error message you are getting ?
Mar 11 13:53:41 smtp postfix/smtp[102]: 08E88B1F2CE: to=<xxx@gmail.com>, relay=none, delay=0.1, delays=0.07/0.02/0.01/0, dsn=4.3.5, status=deferred (Host or domain name not found. Name service error for name=smtp.mydomain.intranet type=A: Host not found)
As docker adds extra_hosts to the /etc/hosts, I guess this happens due to the issue decribed here: https://serverfault.com/a/1004330
Mar 11 13:53:41 smtp postfix/smtp[102]: 08E88B1F2CE: to=<xxx@gmail.com>, relay=none, delay=0.1, delays=0.07/0.02/0.01/0, dsn=4.3.5, status=deferred (Host or domain name not found. Name service error for name=smtp.mydomain.intranet type=A: Host not found)
Ok I was able to reproduce it, I will look into it.
As docker adds extra_hosts to the /etc/hosts, I guess this happens due to the issue decribed here: https://serverfault.com/a/1004330
This solution does not work because it copies the resolv.conf file on image build, and every person resolv.conf file can be different.
Correct. But what if you copy the file on container start? You could even link it.
I tested that on a running container, symlinking /etc/resolv.conf and /etc/hosts to /var/spool/postfix/etc/ and restarted the postfix process but it did not work. I have to investigate this further.
I tested that on a running container, symlinking /etc/resolv.conf and /etc/hosts to /var/spool/postfix/etc/ and restarted the postfix process but it did not work. I have to investigate this further.
This will not work in any case because:
a) The resolv.conf
file is to set the DNS server to use, and this case is about adding an entry to /etc/hhosts
using docker-compose's extra_hosts
config parameter.
b) Adding /etc/hosts
will not work either because postfx does not read it as it does name server queries directly, not through the os by default.
Yes, I found that took last weekend, tested it and it works. Now I need to make sure that changing smtp_host_lookup = native
does not break anything else.
Fixed.
Great. Thx. Works now as expected!