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
MAINTAINER dev<dev@localhost.com>

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 postfix.dev.mail.com" >> 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 = postfix.dev.mail.com'
RUN postconf -e 'mydestination = postfix.dev.mail.com, mail.dev.giftcardmall.com, localhost.localdomain, localhost'
RUN postconf -e 'relayhost = atom.corp.ebay.com'
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 "dev.mail.com   devuser@dev.mail.com" > /etc/postfix/sasl_passwd
RUN postmap /etc/postfix/sasl_passwd

ADD postfix.sh /opt/postfix.sh
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"]

supervisord.conf:

  • Install mysqlclient-python in Docker
  • Docker containers: services vs full applications
  • How to do a custom deploy using ssh with Travis CI?
  • git clone (SSH) gets reaped by supervisord run in docker
  • Setup global environnement variables for all Docker containers
  • webpack-dev-server hot loading not working with boot2docker
  • [supervisord]
    nodaemon=true
    
    [program:postfix]
    command=/opt/postfix.sh
    autostart=true
    autorestart=true
    

    postfix.sh

    #!/bin/bash
    service postfix start
    tail -f /var/log/mail.log
    

    I am trying to install postfix,supervisord and configure postfix to relay email via postfix.dev.mail.com. 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" user@mail.com

    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?

  • How to pull new docker images to openshift cluster nodes from remote private registry?
  • Find out to which removed docker container a volume belonged to
  • How exactly does docker work? (Theory)
  • Run commands on create a new Docker container
  • How to correctly link php-fpm and Nginx Docker containers?
  • Unable to use the “Docker push” command with ECR
  • 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
    use

    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.