We use MUP to deploy our Meteor app, NYBR. MUP creates three docker containers for running the meteor app, nginx reverse proxy and mongo. Like most applications, the need for sending the email came, ideally we should be using Amazon Web Services SES, but getting their approval was a pain in the @$$ and was taking time. So, we did not want to hold back our development and decided to send the email through our own SMTP server until SES was approved.
We installed postfix and were hoping to get to developing and sending beautiful emails to our users. Unfortunately, we were greeted with the Connection refused error.
After trying various things in postfix configuration at,/etc/postfix/main.cf
turns out there is something called docker bridge (docker0) which acts a bridge between your ethernet port and Docker containers so that data can go back and forth.
So you have to listen on the docker0 interface. To do that, type ifconfig
on your host system to find out the bridge address and set your postfix to listen on it.
As you can see in the image above, the IP is 172.17.0.1
In postfix configuration located at /etc/postfix/main.cf
set
inet_interfaces = 172.17.0.1
While you are there, add your actual docker container ip address to mynetworks
mynetworks = 172.17.0.3 172.17.0.5
above two are private ip addresses of my docker containers from which I wish to send email.
You can find the IP address of your docker container by
docker inspect [container_id, container_name]
example
docker inspect my_container_name
Let me know in comments if you would like to learn how to send html emails in meteor.
So, now I know how to configure my host’s postfix installation. But do I need to install something inside the container, like postfix? Let say I run an ubuntu:latest container. I don’t have sendmail installed, so I install postfix (which provides its own sendmail implementation). But then how do I configure the container’s postfix installation?
I have quite a hard time understanding how all this works ^^
You don’t have to install or configure containers postfix or sendmail. The container asks the host to send an email, and we have configured postfix to accept requests from the container.