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 "generic@adress.com generic2@adress2.com" > /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.

Aurelien
  • 688
  • 1
  • 9
  • 22
  • I suggest you look into using this postfix server which runs inside a docker container https://github.com/tomav/docker-mailserver – Scott Stensland Oct 16 '18 at 22:01

3 Answers3

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.

Yuankun
  • 6,875
  • 3
  • 32
  • 34
0

I finally decided to cheat and use Supervisord.

Aurelien
  • 688
  • 1
  • 9
  • 22
0

You could use the following command to start postfix

CMD ["/usr/libexec/postfix/master","-c", "/etc/postfix", "-d"]
Naveen Kerati
  • 951
  • 3
  • 13
  • 29