postfix docker doesn't relay emails

Hi I am trying to create a docker container that relays emails via a smtp server, my Dockerfile is as follows –

FROM ubuntu:trusty

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN echo "postfix postfix/main_mailer_type string Internet site" > preseed.txt
RUN echo "postfix postfix/mailname string" >> preseed.txt
RUN debconf-set-selections preseed.txt
RUN DEBIAN_FRONTEND=noninteractive apt-get install -q -y postfix

RUN apt-get -y install postfix supervisor sasl2-bin opendkim opendkim-tools mailutils vim

RUN postconf -e 'myhostname ='
RUN postconf -e 'mydestination =,, localhost.localdomain, localhost'
RUN postconf -e 'relayhost ='
RUN postconf -e 'smtp_sasl_auth_enable = yes'
RUN postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
RUN postconf -e 'smtp_sasl_security_options ='
RUN echo "" > /etc/postfix/sasl_passwd
RUN postmap /etc/postfix/sasl_passwd

ADD /opt/
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 22 25 110 143 465 587 993 995
CMD ["sh", "-c", "/usr/bin/supervisord","service postfix start"]


  • What's the container of a base docker image?
  • resolve internal DNS in linked docker containers
  • How to add filter in fluentd
  • accessing a docker container from another another container
  • Oracle Instant Client - with Docker and PHP
  • How to run a docker container as a daemon starting the rails project built inside?
  • [supervisord]

    service postfix start
    tail -f /var/log/mail.log

    I am trying to install postfix,supervisord and configure postfix to relay email via I run the container as follows,

    sudo docker run -p 22 -p 25 -p 110 -p 143 -p 465 -p 587 -p 993 -p 995 -i -t 7c9cc85e34c1 /bin/bash

    And run echo "Hello world" | mailx -s "Hello world"

    But I don’t receive the email. If I do the same in a normal ubuntu host, it works fine. I also see that when I run the image as container postfix is not started by default. Is there something I am doing wrong?

  • Terminal (bash?) / Docker: logic behind - and --
  • Get audio from asterisk in docker on Mac?
  • jwilder/nginx-proxy points to the nginx welcome screen
  • Failing to debug Nginx load-balancer
  • Docker, Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • [kubeadm]error updating cni config
  • One Solution collect form web for “postfix docker doesn't relay emails”

    IF you add the /bin/bash at the end of the docker run command it overrides the CMD in the build file.
    To run the supervisord

    sudo docker run -p 22 -p 25 -p 110 -p 143 -p 465 -p 587 -p 993 -p 995 -i -t 7c9cc85e34c1

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.