No description
Find a file
2025-02-09 00:43:47 +00:00
.gitlab-ci.yml Add .gitlab-ci.yml 2025-02-08 23:21:27 +00:00
docker-entrypoint.sh Remove lmdb databases if they already exist (eg. when restarting the container) 2025-02-09 00:43:47 +00:00
Dockerfile remove poorly placed comment 2025-02-09 00:40:31 +00:00
README.md Update README.md 2025-02-09 00:15:23 +00:00

docker-postfix

Simple Docker image to run a Postfix MTA in relay mode


This is a simple, Alpine-based image that runs Postfix in relay mode - that is, it accepts incoming mail and forwards it onto a remote SMTP server somewhere else for further processing.

You might want to do this in the instance where you have a lot of services on one machine that send email and you want one neat and tidy exit point for emails in your system.

Use

This image can be found at registry.git.tdpain.net/pkg/docker-postfix.

It is configured using environment variables:

  • POSTFIX_SENDER_DOMAINS: a whitespace-delimited list of domains to accept within the From header of the email, eg. akpain.net tdpain.net
  • POSTFIX_HOSTNAME: the hostname of this instance of Postfix
  • POSTFIX_RELAY_HOST: the hostname of the upstream relay to forward mail to, eg: smtp.fastmail.com:587
  • POSTFIX_RELAY_USER: username for the relay server
  • POSTFIX_RELAY_PASSWORD: password for the relay server
    • This can also be specified as POSTFIX_RELAY_PASSWORD_FILE where the value of that var corresponds to a file inside the container.

You can then expose whatever ports you might want, or use the container within a Docker network. To expose 127.0.0.1:25, you could use a command like:

docker run -d -p 127.0.0.1:25:25 \
	-e POSTFIX_SENDER_DOMAINS=example.com \
	-e POSTFIX_HOSTNAME=$(hostname)-relay \
	-e POSTFIX_RELAY_HOST=smtp.fastmail.com:587 \
	-e POSTFIX_RELAY_USER=dsfgkjhsd \
	-e POSTFIX_RELAY_PASSWORD=gazpacho \
	registry.git.tdpain.net/pkg/docker-postfix:latest

Prior art

This was directly descended from https://xc2.wb1.xyz/post/how-to-run-a-postfix-mail-server-in-a-docker-container/ and indirectly from https://github.com/bokysan/docker-postfix.