There are many ways to deploy this solution with Docker: docker alone, docker-compose, or docker swarm. Here I describe deployment with docker swarm.
- Docker and Docker Swarm
While Docker Swarm is not strictly required, I recommend it for support of docker secrets. This avoids to store your SMTP password in clear on your docker host. If you have docker running without Swarm, just run docker swarm init (full documentation here). You can also check if your docker host is already in Swarm mode with docker info.
This command requires Docker Swarm.
printf "your password" | docker secret create smtp_password -Strictly speaking, you do not need to clone this entire repository. You'll just need:
- /src/docker-compose-example.yml
- /var/appsettings.json
So you can clone this repository or just download aforementioned files.
- Update
var/appsettings.jsonas needed. Notedocker-compose-example.ymloverridesSmtpForwarder__Authentication__PasswordFileso you don't have to store your SMTP password in clear, and you can ignore this setting inappsettings.jsonfile. - Copy
docker-compose-example.ymltodocker-compose.yml - Update
docker-compose.ymlas needed:- By default, example file assumes container will join an overlay network named
my-attachable-overlay(overlay network and not bridge network to be compatible with docker swarm). You can adapt this (or you can create this network with commanddocker network create -d overlay --attachable my-attachable-overlay).
- By default, example file assumes container will join an overlay network named
If you prefer not to use docker secrets, you can set your SMTP password in clear in docker-compose.yml by replacing SmtpForwarder__Authentication__PasswordFile by SmtpForwarder__Authentication__Password (value is password in clear). Alternatively you can set password directly in appsettings.json.
From directory containing docker-compose.yml:
docker stack deploy -c docker-compose.yml localsmtprelayIf you need to stop it:
docker stack rm localsmtprelayConfigure your local SMTP clients:
- From another container on same docker host: use hostname
localsmtprelayand port 25. - From docker host: use
localhostand port binding set indocker-compose.yml(default: port 25). - From another machine: use docker host IP address.
You don't need to stop current deployment.
- Update file
docker-compose.ymlto reflect new version ofimagefield. - Deploy or update with
docker stack deploy -c docker-compose.yml localsmtprelay