Docker容器中的Postfix无法parsingMX,除非它重新启动一次

我有一个Docker容器中的Postfix实例的问题。 我使用supervisord来确保服务在后台运行。 但是,如果我build立的图像,第一次启动它,并尝试发送邮件,Postfix抱怨说,它不能parsing给定地址的MXlogging( status=deferred (Host or domain name not found. Name service error for name=domain.tld type=MX: Host not found, try again) )。

现在我安装dig以找出它是否是一个DNS问题,但我可以直接解决MX:

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

然后,我开始重新启动postfix,并重新启动service postfix restart ,很惊讶MX问题已经消失。 我把这个问题重复了三次以上,总是一样的。 我必须发出service postfix restart ,使Postfix的工作function齐全。

有人可以解释为什么甚至更好:如何解决这个问题?

提前致谢!

当我尝试在phusion / baseimage上安装postfix时,遇到了同样的问题,它使用runitreplace了ubuntus init.d系统。 如果你发出“service postfix restart”,那么这个脚本在/etc/init.d中运行后缀脚本,而后者会执行很多我不明白的事情。 其中之一是从/ etc复制一堆文件到/ var / spool / postfix / etc,包括resolv.conf。 复制这个文件为我解决了这个问题。 因此,在你的运行脚本中,添加(取自/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 

如果你使用的是VirtualBox虚拟机,你可能会遇到这个bug: https : //www.virtualbox.org/ticket/11540

编辑:

详细说明一下,我在Docker中也遇到了Exim的问题。 我在我的Docker容器中安装了一个备用的DNS工具host ,它在使用-t MX或甚至-t ANY运行时回答了Alogging。 这导致我相信DNS被打破,导致我的VirtualBox的错误。

这不是Postfix或者Docker,它是一个在默认的resolv.conf下的VirtualBox虚拟机上的DNSparsing错误。 在另一个环境中运行相同的软件没有这个问题。