4

I'm trying to build a docker container dedicated to a Postfix SMTP relay. I fail to make it start the postfix service on it after several tries.

Here's the 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"]

The config.sh file contains :

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

I tried to use the "postfix start" command as entrypoint in my dockerfile but the container instantly shuts down with return code 0. I tried to start the container with the CMD by removing the /sbin/postfix start part, my container starts and is stable, but i have to start the postfix service manually. And then my relay works. But that's suboptimal.

I found solutions using supervisord, but i want to keep my container as simple as possible. My goal is to have a light interchangeable relay to send my mails from my application hosted on the docker server.

1

3 Answers 3

5

Postfix v3.3.0 added support for container:

Container support: Postfix 3.3 will run in the foreground with "postfix start-fg".

If you are using a lower version, you might need to use supervisord or an infinite loop or an infinite sleep just to stop the container from exiting.

3
  • Thank you. I will try to dig on this subject.
    – Aurelien
    Mar 27, 2018 at 8:24
  • Sorry i couldn't found a repository with Postfix 3.3, the higher i can found is 3.2.
    – Aurelien
    Mar 28, 2018 at 13:42
  • @Aurelien the default postfix version on ubuntu 18.04 is 3.3
    – Son
    Jul 12, 2019 at 14:34
0

I finally decided to cheat and use Supervisord.

0

You could use the following command to start postfix

CMD ["/usr/libexec/postfix/master","-c", "/etc/postfix", "-d"]

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.