I've a Docker container running on Debian (stretch). I had sendmail
installed through apt-get install sendmail
on the Docker container so that I can send emails from the container.
Here's how my Dockerfile look:
FROM php:5.6-apache
RUN apt-get update && \
apt-get install -y sendmail && \
apt-get clean
And I run some commands to update the host file:
host=$(hostname)
line=$(cat /etc/hosts |grep [1]27.0.0.1)
echo "$line localhost.localdomain $host" >> /etc/hosts
When I'm running the container on my local dev machine (Windows) through Virtualbox, I can send emails directly using the sendmail
command in bash without issues. I can receive those emails in my mailbox.
However, when I run the container on a cloud instance (in my case on Digital Ocean), running the same sendmail
command in bash doesn't send emails. There are no errors or whatsoever. The sendmail
command just returned as though the email was sent successfully, but I never receive it in my mailbox.
When I run mailq in the Docker container on my cloud instance, I could see the following error message:
Mon Jun 25 02:05 <www-data@localhost.localdomain> (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo)
There are no error messages in mailq in the same container when running on my local computer.
Shouldn't the Docker container work the same even on a different host machine?
Why does sendmail
work when running in the container on my local computer, but not when running it on a cloud instance?