我正在尝试构建专用于Postfix SMTP中继的docker容器。
经过几次尝试后,我无法使其启动后缀服务。

这是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 "[email protected] [email protected]" > /etc/postfix/generic
postmap /etc/postfix/generic

我试图在dockerfile中使用“postfix start”命令作为入口点,但是容器立即关闭,返回码为0。
我试图通过删除/sbin/postfix start部分来启动带有CMD的容器,我的容器已启动且稳定,但是我必须手动启动postfix服务。然后我的中继工作。
但这不是最理想的。

我找到了使用supervisored的解决方案,但我想让我的容器尽可能简单。
我的目标是要有一个轻巧的可互换中继,以便从托管在docker服务器上的应用程序发送邮件。

最佳答案

Postfix v3.3.0添加了support for container:



如果使用的是较低版本,则可能需要使用supervisored或无限循环或无限睡眠来阻止容器退出。

关于docker - Dockerizing Postfix中继服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49495679/

10-15 19:13