大网数据广告活动
服务器运维问答

Postfix in Docker: Host or domain name not found (DNS and Docker)

· 52CE 我爱测

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…

问题原文

原帖链接 · Stefaan Neyts · CC BY-SA 4.0

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 '[email omitted]' --mail-rcpt '[email omitted]' --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  [email omitted]
(Host or domain name not found. Name service error for name=mail.level27.be type=A: Host not found, try again)
                                         [email omitted]
-- 0 Kbytes in 1 Request.

已采纳解答

原帖链接 · Stefaan Neyts · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。