We need the SMTP server for our mailer service. We use the juanluisbaptiste/postfix image with the Postfix mail server. The server also has to be restarted if it fails and we set the restart policy to always. Look at the following code:
smtp:
image: juanluisbaptiste/postfix
restart: always
environment:
- SMTP_SERVER=smtp.example.com
- SMTP_USERNAME=admin@example.com
- SMTP_PASSWORD=password
- SERVER_HOSTNAME=smtp.example.com
ports:
- "2525:25"
We also configure the server using the environment variables and set the server name, username, password, and a hostname. To test the mail server, we forward port 25 of the mail server to a local 2525 port.