2

I'm running Postfix 3.4.8 on Debian 10 (buster) in Docker 19.03.5. Postfix is configured as a smarthost. It relays emails to the SMTP server of our ISP.

If I configure the relayhost setting with the domain name of the SMTP server, in my case [mail.level27.be]:587, then I get this error when sending mail:

Host or domain name not found. Name service error for name=mail.level27.be type=A: Host not found, try again

If I configure the relayhost setting with the IP of the SMTP server, in my case [185.3.216.85]:587, it works!

I guess it's a DNS issue. How can I make it work with the domain name in stead of the IP?

The Docker image is build with this command:

docker build --pull -t mypostfix .

Here is the Dockerfile:

FROM debian:10
EXPOSE 25

RUN apt-get update
RUN apt-get -y install libsasl2-modules postfix

RUN postconf -X 'mynetworks' \
    && postconf -e 'mynetworks_style = subnet' \
    && postconf -X 'mydestination' \
    && postconf -e 'remote_header_rewrite_domain =' \
    && postconf -e 'inet_protocols = ipv4' \
    && postconf -e 'relayhost = [mail.level27.be]:587' \
    && postconf -e 'smtp_use_tls = yes' \
    && postconf -e 'smtp_sasl_auth_enable = yes' \
    && postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd' \
    && postconf -e 'smtp_sasl_security_options = noanonymous' \
    && postconf -e 'maillog_file = /dev/stdout' \
    && echo "mail.level27.be   username:password" > /etc/postfix/sasl_passwd \
    && chown root:root /etc/postfix/sasl_passwd \
    && chmod 600 /etc/postfix/sasl_passwd \
    && postmap /etc/postfix/sasl_passwd

CMD postfix start-fg

The Docker container is started with this command:

docker run --rm -d -p 25:25 mypostfix

The email is sent on the Docker host with this curl command:

echo "This is some mail content." > /tmp/email.txt

curl --url 'smtp://localhost:25' --mail-from 'xxx.yyy@zzz.be' --mail-rcpt 'xxx.yyy@zzz.be' --upload-file /tmp/email.txt

The error can be seen by running postqueue -p in the container:

root@mypostfix:/# postqueue -p
-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
DBB26A05886      256 Wed Feb 19 14:45:42  xxx.yyy@zzz.be
(Host or domain name not found. Name service error for name=mail.level27.be type=A: Host not found, try again)
                                         xxx.yyy@zzz.be
-- 0 Kbytes in 1 Request.
1

Looks like you have issue with DNS resolving inside container. There is good blog post, where described your issue, check it out.

1
  • Please include the pertinent sections of the blog post in your answer in case the link goes cold later. – duct_tape_coder Feb 21 '20 at 2:12
1

Postfix runs several processes with a chroot to /var/spool/postfix. This means that system-files, like /etc/resolv.conf for DNS resolving, should be found at /var/spool/postfix/etc/resolv.conf.

In order to get it working, I had to copy this file to the correct location during startup:

CMD cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf && postfix start-fg

WARNING: Do not copy it during the build, because you may end up with a resolv.conf of your build-server in stead of a resolv.conf of your production-server.

3
  • This will not work because you are copying the file on image build and that file could be different for each user. It woud make more sense to do it at run time on the start script. – Juancho Mar 11 at 17:25
  • 1
    Dear @Juancho, the CMD is executed at runtime, not at build time. You are probably mixing up with RUN, which is executed at build time, not at runtime. Greets – Stefaan Neyts Mar 15 at 20:41
  • Oops you are right, without the square brackets it looks as a Dockerfile instruction at first sight. My apologies. – Juancho Mar 17 at 21:25

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.