I have a docker container running php and apache. The host is in an AWS instance which has the docker instance running. I am unable to send an email from the docker terminal. Is there any way to send an email from docker instance using sendmail which uses the docker's host's configuration?
The following command sends an email from host but doesn't send an email from docker instance. No error is given either.
echo "Subject: Testing Email" | cat - text | /usr/lib/sendmail -F abc.pqr@domain.com -t abc.pqr@domain.com
EDIT: Please see xuhdev answer for more info and how to set up mail forwarder. My answer can be used to setup sendmail instead of postfix on host.
EDIT #2: Add firewall rule to allow smtp traffic from docker
I have made a similiar setup as the tarun mittal as following:
in docker host, modified the /etc/mail/sendmail.mc to include listening on the docker0 interface (in contrast to all interfaces in tarun's answer - bold is added line)
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=172.17.42.1')dnl
Allow the access from the docker containers to docker interface in firewall iptables -I INPUT -s 172.17.0.0/24 -d 172.17.42.1 -dport 25 -j ACCEPT
in /etc/mail/access I have added at the end to allow all docker instances to send emails and makemap hash /etc/mail/access < /etc/mail/access to compile database
/// EDITED - USE BELOW AS DOCKER WILL GO TO 172.17.1.X after many rebuilds
/// OLD - Connect:172.17.0 RELAY
Connect:172.17 RELAY
Finally restart sendmail - service sendmail restart
Adding a fully qualified domain name to the Docker host name in /etc/hosts does the trick for me:
To me it looks like this:
You can also use this bash script to automatically update this line:
Reference: http://hjk41.azurewebsites.net/2015/09/25/using-sendmail-inside-docker/
You have to point inet_interfaces to docker bridge (docker0) in post fix config located at set /etc/postfix/main.cf
inet_interfaces =
More internal working detail at sending email from docker via postfix installed on host
Note: use ifconfig command to get the docker bridge address
According to the Sendmail manual we may use
sendmail -bd
command to run a service. But it exists with zero status. So...Also you may use supervisord. I use this config:
And test it:
Don't forget to check Spam folder.
Nowhere in your Dockerfile is sendmail (or any other mail agent) installed. The host, however, apparently does have sendmail available. The "best" or most Docker-like solution is to spin up another container that runs an MTA (like postfix or exim), and configure your application to use that.
building on previous answers,
create config/sendmail_config.sh with:
change yum for apt-get on debian based containers
then in Dockerfile add:
I want sendmail with my php util so I can stick it anywhere with out having to link to another MTA container or host to complete the task.
I run sh sendmail_config.sh, and then run my php util.