# docker-mailserver — Production-Ready Self-Hosted Email in Docker > docker-mailserver is a full-featured mail server stack running inside a single Docker container. It bundles Postfix, Dovecot, Amavis, SpamAssassin, and OpenDKIM into a cohesive setup that is straightforward to deploy and maintain with environment variables and a helper CLI. ## Install Save as a script file and run: # docker-mailserver — Production-Ready Self-Hosted Email in Docker ## Quick Use ```bash docker run -d --name mailserver -p 25:25 -p 143:143 -p 587:587 -p 993:993 -v ./docker-data/dms/mail-data:/var/mail -v ./docker-data/dms/mail-state:/var/mail-state -v ./docker-data/dms/config:/tmp/docker-mailserver -e ENABLE_SPAMASSASSIN=1 -e ENABLE_CLAMAV=1 ghcr.io/docker-mailserver/docker-mailserver:latest ``` ## 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.sh` CLI 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. ## Sources - https://github.com/docker-mailserver/docker-mailserver - https://docker-mailserver.github.io/docker-mailserver/latest/ --- Source: https://tokrepo.com/en/workflows/c1eeb468-4105-11f1-9bc6-00163e2b0d79 Author: Script Depot