Scripts2026年4月22日·1 分钟阅读

Docker Mailserver — Production-Ready Self-Hosted Email Server

A full-featured mail server running inside a single Docker container with SMTP, IMAP, LDAP, antispam, antivirus, and more.

Introduction

Docker Mailserver provides a complete, production-ready email server packaged in a single Docker container. It bundles Postfix (SMTP), Dovecot (IMAP/POP3), Rspamd or Amavis (antispam), ClamAV (antivirus), and OpenDKIM into one cohesive stack so you can run your own mail infrastructure without stitching services together manually.

What Docker Mailserver Does

  • Provides SMTP (Postfix) and IMAP/POP3 (Dovecot) in a single container
  • Filters spam with Rspamd or SpamAssassin and scans for viruses with ClamAV
  • Handles DKIM signing, SPF, and DMARC for email authentication
  • Supports LDAP and OAuth2 for centralized user management
  • Manages TLS certificates automatically via Let's Encrypt integration

Architecture Overview

The container runs a supervisor process that orchestrates Postfix for mail transfer, Dovecot for mailbox access, and Rspamd (or Amavis) for content filtering. Incoming mail flows through Postfix, gets scanned by the spam and virus filters, then lands in Dovecot-managed Maildir storage. Configuration is driven by environment variables in mailserver.env and optional config files mounted into the container. A built-in setup CLI handles account creation, alias management, and DKIM key generation.

Self-Hosting & Configuration

  • Deploy with Docker Compose using the official docker-compose.yml template
  • Set your domain, hostname, and TLS mode in mailserver.env
  • Mount /var/mail and /var/mail-state volumes for persistent storage
  • Generate DKIM keys with docker exec mailserver setup config dkim
  • Configure DNS records (MX, SPF, DKIM, DMARC) to complete the setup

Key Features

  • Single container design keeps deployment and upgrades simple
  • Rspamd provides modern Bayesian filtering with a web UI for statistics
  • Supports virtual users, aliases, and relay hosts out of the box
  • Fail2ban integration blocks brute-force login attempts automatically
  • Extensive documentation covers every configuration option in detail

Comparison with Similar Tools

  • Mailcow — full-featured with a web UI but requires more resources and multiple containers
  • Mailu — similar Docker-based approach but uses a microservice architecture with separate containers per service
  • Postal — focused on transactional/outbound mail delivery rather than personal mailboxes
  • iRedMail — installs directly on the host OS without containerization

FAQ

Q: How much RAM does Docker Mailserver need? A: The base setup runs on 512 MB RAM. Enabling ClamAV adds roughly 1-2 GB. You can disable ClamAV on low-memory servers.

Q: Can I use it with an existing reverse proxy? A: Yes. Ports 25, 143, 465, 587, and 993 need to be exposed directly (mail protocols cannot be reverse-proxied like HTTP), but the optional web-based admin tools can sit behind Nginx or Traefik.

Q: Does it support multiple domains? A: Yes. Add accounts for any domain and configure the corresponding DNS records. The server handles virtual domains natively.

Q: How do I migrate from another mail server? A: Use imapsync or dsync to copy mailboxes into the Dovecot store. Account credentials can be imported via the setup CLI or by editing the postfix-accounts.cf file directly.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产