Introduction
Running your own email server has a reputation for being complex. docker-mailserver packages the entire stack into a single container image with sensible defaults, so you can self-host email for a custom domain with SMTP, IMAP, spam filtering, DKIM signing, and TLS in a few minutes.
What docker-mailserver Does
- Provides SMTP (Postfix) and IMAP (Dovecot) in one container
- Includes spam filtering via SpamAssassin and optional ClamAV virus scanning
- Handles DKIM, SPF, and DMARC signing and validation automatically
- Supports multiple domains and virtual mailbox users
- Ships a
setup.shCLI for managing accounts, aliases, and DKIM keys
Architecture Overview
The container runs a supervisor process that manages Postfix, Dovecot, OpenDKIM, Amavis, and optional services like Fail2Ban and Fetchmail. Mail data, state, and configuration are stored in three bind-mounted volumes. Environment variables control which features are enabled, and the setup CLI writes config files inside the container that persist via volumes.
Self-Hosting & Configuration
- Requires Docker or Podman and a host with ports 25, 143, 587, and 993 open
- DNS must have MX, SPF, DKIM, and DMARC records pointing to the server
- TLS certificates can be provided manually or obtained via Let's Encrypt integration
- User accounts and aliases are managed with
setup.sh email add user@domain - All tuning is done through environment variables in the Compose file
Key Features
- Single-container deployment with no external database dependency
- Built-in Fail2Ban for brute-force protection on SMTP and IMAP
- Automatic DKIM key generation and DNS record guidance
- Optional Fetchmail support for pulling from external accounts
- Active community with detailed documentation and quick issue response
Comparison with Similar Tools
- Mailcow — Full web UI with SOGo groupware; docker-mailserver is leaner with no web interface
- Mail-in-a-Box — Ubuntu-based all-in-one server; docker-mailserver runs in containers for easier isolation
- Mailu — Python-based containerized mail; docker-mailserver uses traditional MTA components (Postfix/Dovecot)
- iRedMail — Installs directly on a VM; docker-mailserver offers a more portable container-native approach
FAQ
Q: Do I need a static IP to run a mail server? A: Yes. Most receiving servers check reverse DNS, so a static IP with a matching PTR record is essential for deliverability.
Q: Can I use this with an external SMTP relay like SendGrid?
A: Yes. Set RELAY_HOST and related environment variables to route outbound mail through a relay.
Q: How do I back up mailboxes?
A: Back up the mail-data and mail-state volumes. Mailbox data is stored in standard Maildir format.
Q: Does it support LDAP for user accounts? A: Yes. LDAP authentication is supported as an alternative to the built-in file-based user management.