我正在尝试构建一个专用于 Postfix SMTP 中继的 docker 容器。
经过多次尝试,我未能让它在其上启动 postfix 服务。
这是 dockerfile
FROM centos:centos7
LABEL Author = "Aurelien HUGON
LABEL Description = "DOCKERFILE : Creates a Docker Container for a Relay Postfix smtp server"
#Update and soft
RUN yum update -y
RUN yum install -y nano postfix
#Clean install
RUN yum clean all
#Config
COPY /cfg/config.sh /
RUN chmod +x config.sh
RUN ./config.sh
RUN touch /var/log/maillog
CMD ["sh", "-c", "/sbin/postfix start", "tail -f /var/log/maillog"]
config.sh 文件包含:
postconf -e 'myhostname = myserverhostname'
postconf -e 'mydomain = domain.com'
postconf -e 'myorigin = $mydomain'
postconf -e 'smtp_generic_maps = hash:/etc/postfix/generic'
postconf -e 'mynetworks = 127.0.0.1/32 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 [::1]'
postconf -e 'mynetworks_style = class'
postconf -e 'inet_interfaces = all'
postconf -e 'relayhost = [dedicated SMTP server]'
echo "generic@adress.com generic2@adress2.com" > /etc/postfix/generic
postmap /etc/postfix/generic
我试图在我的 dockerfile 中使用“postfix start”命令作为入口点,但容器立即关闭并返回代码 0。
我试图通过删除
/sbin/postfix start
来使用 CMD 启动容器。部分,我的容器启动并稳定,但我必须手动启动 postfix 服务。然后我的继电器工作。但那是次优的。
我找到了使用 supervisord 的解决方案,但我想让我的容器尽可能简单。
我的目标是拥有一个轻量级的可互换中继,以从托管在 docker 服务器上的应用程序发送我的邮件。
最佳答案
后缀 v3.3.0 添加 support for container :
Container support: Postfix 3.3 will run in the foreground with "postfix start-fg".
如果您使用的是较低版本,则可能需要使用 supervisord 或无限循环或无限 sleep 来阻止容器退出。
关于Dockerizing Postfix 中继服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49495679/