Score:1

Postfix "Name service error for name=dovecot" in docker-compose

in flag

Context

My docker-compose --version is 2.13.0

I have created a reproducer in https://github.com/Losmoges/postfix-dovecot-lmtp-reproducer

My trial has three docker services in the compose file: postfix, dovecot, and client. They share a network through the bridge driver.

  • Postfix is configured to forward incoming emails to dovecot through the virtual_transport = lmtp:dovecot:24 setting in the main.cf configuration.
  • Dovecot is configured to receive connections through the service lmtp / inet_listener lmtp / port = 24 setting in the dovecot.conf configuration.
  • I can send an email through Postfix by executing echo test | msmtp [email protected] in the client container. Its msmtp is configured to connect to host postfix through a msmtprc configuration file.

This yields the following result in the Postfix queue, which I can inspect by running postqueue -p in the Postfix container.

Error

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
DEC4F3DCBE      245 Fri Dec 16 19:41:17  [email protected]
(Host or domain name not found. Name service error for name=dovecot type=A: Host not found, try again)
                                         [email protected]

Workaround

When I find the IP address of the Dovecot container through docker inspect and enter it into the Postfix configuration, for example as virtual_transport = lmtp:172.18.0.4:24, everything works as expected. In this case, the command postqueue -p gives Mail queue is empty (after sending an email through msmtp)

Questions

Why does virtual_transport = lmtp:dovecot:24 not work? Did I misconfigure something? Any form of name-lookup, such as nslookup dovecot (after installing dnsutils) in the Postfix container works just fine and returns the IP address of the Dovecot container. Does Postfix do its own separate domain-name resolution? If so, how can I force it to use the default domain-name resolution?

Edit: Solution in Answer

I added the following line to the Dockerfile for the Postfix image

RUN sed -i'' -e 's/^lmtp .*/lmtp      unix  -       -       n       -       -       lmtp/g' /etc/postfix/master.cf
Score:1
pt flag

Why does virtual_transport = lmtp:dovecot:24 not work?

In your master.cf, you have lmtp configured to run in a chroot environment:

# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (no)    (never) (100)
lmtp      unix  -       -       n       -       -       lmtp

The chroot environment doesn't have access to the container's /etc/resolv.conf, so it doesn't know how to resolve hostnames. The lmtp configuration defaults to run in a chrooted environment because a typical configuration uses unix sockets to communicate, so hostname resolution isn't an issue.

The simplest fix is just to configure lmtp to not run in chroot environment:

lmtp      unix  -       -       y       -       -       lmtp

With this change, mail is delivered correctly:

postfix_1  | Dec 16 21:47:15 8d74be7a5951 postfix/smtpd[598]: connect from unknown[172.28.0.1]
postfix_1  | Dec 16 21:47:15 8d74be7a5951 postfix/smtpd[598]: 9131638672DA: client=unknown[172.28.0.1]
postfix_1  | Dec 16 21:47:15 8d74be7a5951 postfix/qmgr[582]: 9131638672DA: from=<[email protected]>, size=434, nrcpt=1 (queue active)
postfix_1  | Dec 16 21:47:15 8d74be7a5951 postfix/smtpd[598]: disconnect from unknown[172.28.0.1] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
dovecot_1  | Dec 16 21:47:15 lmtp(16): Info: Connect from 172.28.0.3
dovecot_1  | Dec 16 21:47:15 lmtp([email protected])<16><+A19J2PnnGMQAAAAqj6rOA>: Info: msgid=<20221216164715.079491@rocket>: saved mail to INBOX
postfix_1  | Dec 16 21:47:15 8d74be7a5951 postfix/lmtp[597]: 9131638672DA: to=<[email protected]>, relay=dovecot[172.28.0.2]:24, delay=0.09, delays=0.07/0/0/0.01, dsn=2.0.0, status=sent (250 2.0.0 <[email protected]> +A19J2PnnGMQAAAAqj6rOA Saved)
dovecot_1  | Dec 16 21:47:15 lmtp(16): Info: Disconnect from 172.28.0.3: Logged out (state=READY)
postfix_1  | Dec 16 21:47:15 8d74be7a5951 postfix/qmgr[582]: 9131638672DA: removed

One alternative would be to configure a shared unix socket between the dovecot and postfix containers, and use that for communication rather than an inet connection.

A second alternative would be to run the lmtp container in the same network namespace as the postfix container, in which case you could simpler use the hostname localhost.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.