Answer the question
In order to leave comments, you need to log in
How do you solve the problem of the lack of a local smtp server in docker?
There is a bunch of different software that sends emails through local smtp without authorization, for example, almost all php scripts through the mail function
There is no local smtp in the docker by default, as it contradicts the one process one container paradigm. The obvious solutions in my opinion are 2
1) Put the server in the container with the smtp application and run it there in the foreground in front of the application itself.
Of the problems that no one monitors smtp servers, whether it fell or not, then you also need to install some sort of supervisor.
Two processes per container, identified as a pain in deployment automation.
2) For php, install some kind of ssmtp, which will replace the sendmail binary specified in php.ini and will send letters through an external service (its own gmail or mandrill).
Of the minuses in general, the loss of mail if the external service is not working or there are problems with the network before it.
You can also set up sending through an external service in the application itself if there is such an option in it, but again, the loss of mail is very critical.
Probably the ideal solution would be to run the smtp server in a separate container and forward port 25 to the localhost of the container with the application.
But somehow it was not possible to google such a solution for the docker compose right off the bat.
Answer the question
In order to leave comments, you need to log in
Well, in general, you answered everything yourself correctly.
I use the 2nd option you mentioned. A Dockerfile
layer with is added to ssmtp
and that's it. As a ENTRYPOINT
small sh-script that configures s ssmtp
when the container starts, depending on the environment variables. All emails are sent to the external central Postfix, which is already running the whole thing with DKIM signatures and other email bells and whistles.
If you put this external Postfix on the same machine where your application is running, then the probability of loss is the same as in the "traditional" case without Docker (after all, Postfix or Exim are still running on your machine).
Also, as an option, if possible, you can provide retries for sending email in the application code itself, if this is so critical.
Regarding an example docker-compose.yml
:
version: '3'
services:
fpm:
container_name: fpm
image: my/app
depends_on:
- mailserver
expose:
- "9000" # php-fpm
environment:
- SMTP_SERVER=mailserver:587
- [email protected]
- SMTP_PASSWORD=qweqweqwe
nginx:
container_name: nginx
image: nginx:stable-alpine
depends_on:
- fpm
ports:
- "80:80" # http
volumes:
- .dev/nginx.vhost.conf:/etc/nginx/conf.d/default.conf:ro
mailserver:
container_name: mailserver
image: tvial/docker-mailserver:v2
hostname: mail
domainname: mydomain.test
ports:
- "25:25" # smtp
- "143:143" # imap
- "587:587" # smtp-auth
- "993:993" # imap-secure
volumes:
- .dev/mail/accounts.cf:/tmp/docker-mailserver/postfix-accounts.cf:ro
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question