Dockerizing Postfix 中继服务器

标签 docker dockerfile postfix

我正在尝试构建一个专用于 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/

相关文章:

php - 使用带有 alpine php 图像的 docker 更改 php.ini 中的值

docker - 使用 lint 命令构建 docker go 应用程序

docker - 我可以隔离docker swarm中的一对服务吗?

centos - 检查安装的 iRedMail 版本

linux - 这个后缀日志代表什么?

php - Mail-Tester.com : Freemail in Reply-To, 但不是来自

docker - 无法连接到 unix :///var/run/docker. socks 上的 Docker 守护进程。 docker 守护进程是否正在运行?在 Dockerfile 中

docker - 如何知道使用了哪个命令或组合文件来启动 Docker 容器?

apache - 无法使用 docker 自动启动 apache

angular - npm run 不通过 --configuration 来构建任务