泊坞窗容器内配置sendmail容器内、泊坞窗、sendmail

2023-09-11 23:53:33 作者:怪我先动情

我有运行PHP和Apache一个泊坞窗容器。主机是在AWS实例有泊坞窗实例中运行。我无法从泊坞窗终端发送电子邮件。有没有什么办法可以使用​​sendmail,它使用泊坞窗的主机的配置从泊坞窗例如发送电子邮件?

下面的命令从主机发送一封电子邮件,但没有从泊坞窗例如发送电子邮件。没有错误,给出两种。

 回声主题:测试电子邮件|猫 - 文| / usr / lib中/ sendmail的-F abc.pqr@domain.com -t abc.pqr@domain.com
 

解决方案

我要做的就是配置主机MTA对 docker0 倾听并在容器中安装ssmtp中桥的sendmail在容器与主机MTA。运行在主机上的MTA的原因是,系统(临界)的错误可以被发送到管理的邮箱。要在容器中不运行的MTA的原因是,它是一个重复过程作为主机系统已经运行在MTA

在主机上,我使用的后缀。所有我们需要做的是配置后缀对 docker0 倾听和接受泊坞容器传出邮件。编辑文件 /etc/postfix/main.cf文件 docker0 IP地址添加到 inet_interfaces 所以它接受来自泊坞容器连接。此外,添加泊坞窗容器的网络地址 mynetworks中使泊坞容器是合法的,通过主机上的后缀的服务器发送邮件。 (参考和更多详细信息)

要在容器中使用sendmail,安装ssmtp中并设置 FromLineOverride 被允许的,而 mailhub的的IP地址主机在 /etc/ssmtp/ssmtp.conf 的。您可以设置 mailhub的是一个符号,如 SMTP服务器然后运行容器 - 添加主机选项,如本的 Dockerfile (与运行 - 添加主机SMTP服务器:您-docker0地址)。这将配置一个可用的sendmail在容器中实际上使用的主机MTA发送邮件。

如堡垒般的10座日本小屋

I have a docker container running php and apache. The host is in an AWS instance which has the docker instance running. I am unable to send an email from the docker terminal. Is there any way to send an email from docker instance using sendmail which uses the docker's host's configuration?

The following command sends an email from host but doesn't send an email from docker instance. No error is given either.

echo "Subject: Testing Email" | cat - text | /usr/lib/sendmail -F abc.pqr@domain.com -t abc.pqr@domain.com

解决方案

What I do is to configure the host MTA to listen on docker0 and install ssmtp in the container to bridge sendmail in the container with the host MTA. The reason to run an MTA on the host is that system (critical) errors can be sent to the admin's mailbox. The reason to not run MTA in the container is that it is a duplicated process as the host system already runs an MTA.

On the host, I used postfix. All we need to do is to configure postfix to listen on docker0 and accept outgoing mails from Docker containers. Edit the file /etc/postfix/main.cf and add the docker0 IP address to inet_interfaces so it accepts connections from Docker containers. Also, add the network addresses of Docker containers to mynetworks so that Docker containers are legal to send mails via the postfix server on the host. (reference and more details)

To use sendmail in containers, install ssmtp and set FromLineOverride to be permitted and and mailhub to the IP address of the host in /etc/ssmtp/ssmtp.conf. You can set mailhub to be a symbol such as smtp-server and then run the container with --add-host option, as shown in this Dockerfile (run it with --add-host smtp-server:your-docker0-address). This would configure a usable sendmail in containers which would actually use the host MTA to send mails.