Postfix can run in Docker containers for SMTP relay, mail routing, and full mail server deployments. Note: There is no official Postfix Docker image; several community-maintained images are available.
| Image | Description | Size | Best For |
|---|---|---|---|
| juanluisbaptiste/postfix | Simple SMTP TLS relay | ~50 MB | Outbound relay |
| boky/postfix | Full-featured Postfix | ~100 MB | Production mail servers |
| eeacms/postfix | Rocky Linux-based relay | ~200 MB | Enterprise environments |
| catatnight/postfix | Lightweight relay | ~50 MB | Simple relay needs |
| tvial/postfix | Docker mail relay | ~80 MB | Docker Swarm/K8s |
For outbound mail relay (no authentication):
docker run -d \
--name postfix \
-e SMTP_RELAY_SERVER=smtp.example.com:587 \
-e MAILNAME=example.com \
juanluisbaptiste/postfix:latest
For a complete Postfix MTA:
docker run -d \
--name postfix \
-p 25:25 \
-p 587:587 \
-e MAILNAME=example.com \
-e SMTP_RELAY_SERVER=smtp.example.com:587 \
-e SMTP_RELAY_USERNAME=user@example.com \
-e SMTP_RELAY_PASSWORD=secret \
boky/postfix:latest
Purpose: Simple SMTP TLS relay server
Features:
Usage:
docker run -d \
--name postfix-relay \
-e SMTP_RELAY_SERVER=smtp.gmail.com:587 \
-e MAILNAME=example.com \
juanluisbaptiste/postfix:latest
GitHub: https://github.com/juanluisbaptiste/docker-postfix
Purpose: Full-featured Postfix MTA
Features:
Usage:
docker run -d \
--name postfix \
-p 25:25 \
-p 587:587 \
-e MAILNAME=example.com \
-e DB_HOST=mysql \
-e DB_USER=postfix \
-e DB_PASSWORD=secret \
-e DB_NAME=postfixdb \
boky/postfix:latest
GitHub: https://github.com/bokysan/docker-postfix
Purpose: Enterprise SMTP relay
Features:
Usage:
docker run -d \
--name postfix \
-e SMARTHOST=smtp.example.com:587 \
-e MAILNAME=example.com \
eeacms/postfix:latest
Docker Hub: https://hub.docker.com/r/eeacms/postfix
version: '3.8'
services:
postfix:
image: juanluisbaptiste/postfix:latest
container_name: postfix-relay
hostname: mail.example.com
environment:
- SMTP_RELAY_SERVER=smtp.example.com:587
- MAILNAME=example.com
ports:
- "25:25"
restart: unless-stopped
networks:
- mail-network
networks:
mail-network:
driver: bridge
version: '3.8'
services:
postfix:
image: boky/postfix:latest
container_name: postfix-mta
hostname: mail.example.com
domainname: example.com
ports:
- "25:25"
- "587:587"
environment:
- MAILNAME=example.com
- SMTP_RELAY_SERVER=smtp.example.com:587
- SMTP_RELAY_USERNAME=user@example.com
- SMTP_RELAY_PASSWORD=secret_password
- DB_HOST=mysql
- DB_USER=postfix
- DB_PASSWORD=secure_password
- DB_NAME=postfixdb
volumes:
- postfix-data:/var/spool/postfix
- ./config:/etc/postfix/custom
restart: unless-stopped
depends_on:
- mysql
networks:
- mail-network
mysql:
image: mariadb:10.11
container_name: postfix-mysql
environment:
- MYSQL_ROOT_PASSWORD=root_password
- MYSQL_DATABASE=postfixdb
- MYSQL_USER=postfix
- MYSQL_PASSWORD=secure_password
volumes:
- mysql-data:/var/lib/mysql
restart: unless-stopped
networks:
- mail-network
volumes:
postfix-data:
mysql-data:
networks:
mail-network:
driver: bridge
Common environment variables across images:
| Variable | Description | Example |
|---|---|---|
MAILNAME |
Mail server hostname | mail.example.com |
SMTP_RELAY_SERVER |
Upstream SMTP relay | smtp.example.com:587 |
SMTP_RELAY_USERNAME |
Relay authentication user | user@example.com |
SMTP_RELAY_PASSWORD |
Relay authentication password | secret |
DB_HOST |
Database host (if using) | mysql |
DB_USER |
Database username | postfix |
DB_PASSWORD |
Database password | secret |
DB_NAME |
Database name | postfixdb |
Recommended volume mounts:
volumes:
# Mail queue persistence
- postfix-data:/var/spool/postfix
# Custom configuration
- ./postfix-config:/etc/postfix/custom
# SSL certificates
- ./ssl:/etc/ssl/certs:ro
# Logs
- ./logs:/var/log
| Port | Protocol | Purpose |
|---|---|---|
| 25 | TCP | SMTP (mail relay) |
| 587 | TCP | Submission (client mail) |
| 465 | TCP | SMTPS (legacy SSL) |
services:
postfix:
image: boky/postfix:v7.0.0 # Not :latest
services:
postfix:
deploy:
resources:
limits:
memory: 512M
cpus: '1.0'
services:
postfix:
healthcheck:
test: ["CMD", "postfix", "status"]
interval: 30s
timeout: 10s
retries: 3
services:
postfix:
read_only: true
tmpfs:
- /tmp
- /var/spool/postfix
cap_drop:
- NET_RAW
security_opt:
- no-new-privileges:true
# View logs
docker logs postfix
# Follow logs
docker logs -f postfix
# Last 100 lines
docker logs --tail 100 postfix
# Access shell
docker exec -it postfix bash
# Check Postfix status
docker exec postfix postfix status
# View mail queue
docker exec postfix mailq
Connection refused:
Relay access denied:
TLS errors:
Any questions?
Feel free to contact us. Find all contact information on our contact page.