Post

docker-mailserver: Self-Hosted, Full-Featured Mail Solution with Docker

Explore docker-mailserver, a production-ready, secure, and flexible mail server that runs in Docker. Perfect for privacy and control.

docker-mailserver: Self-Hosted, Full-Featured Mail Solution with Docker

docker-mailserver: Self-Hosted, Full-Featured Mail Solution with Docker

Are you tired of relying on third-party email providers? Want full control of your mail environment without giving up convenience or security? You’re not alone.

Welcome to the world of docker-mailserver – a powerful, production-ready mail server that works entirely in Docker, no rocket science required.


Why You Need a Self-Hosted Mail Server

Let’s face it – handing over your emails to companies like Google or Microsoft means sacrificing privacy. Whether you’re running a startup, freelancing, or just value your digital freedom, hosting your own email server gives you complete control over your data.

And yes, self-hosted email doesn’t have to be a nightmare.


Meet docker-mailserver

docker-mailserver is a fully-fledged, feature-rich, and secure mail server setup – all containerized and easy to deploy. With over 11K GitHub stars and contributions from hundreds of developers, it’s one of the most trusted open-source mail server stacks.

It combines the best open-source tools into a seamless Docker-based experience.

🚀 Built for production use, docker-mailserver lets you go from zero to a working mail system in under 10 minutes.


Key Highlights of the Project

  • One-click deployment via Docker or Docker Compose
  • Supports SMTP, IMAP, POP3 out of the box
  • Spam filtering, antivirus, DKIM, SPF, and DMARC
  • Scripted user management
  • Lightweight and production-grade
  • Secure by default

Getting Started

Setting up a mail server can be intimidating. Not with this one.

Prerequisites

  • Docker Engine (v20+ recommended)
  • Docker Compose (for ease of use)
  • A domain name (e.g., mail.yourdomain.com)
  • Some basic Linux know-how

Supported Operating Systems and Environments

  • Ubuntu (18.04, 20.04, 22.04)
  • Debian (10, 11, 12)
  • Red Hat-based distros (CentOS, Rocky, AlmaLinux)
  • Runs great on VPS providers like DigitalOcean, Linode, Hetzner, and AWS EC2

System Requirements

  • At least 1 vCPU
  • 2 GB RAM minimum
  • 10+ GB disk space (email storage dependent)
  • Static public IP address is a plus

Core Features of docker-mailserver

Modular & Configurable Mail Server

Behind the scenes, docker-mailserver uses:

  • Postfix (SMTP)
  • Dovecot (IMAP/POP3)
  • Rspamd (Spam Filtering)
  • Amavis / ClamAV (Antivirus)
  • OpenDKIM / OpenDMARC (Email Authentication)
  • Fail2Ban (Intrusion Prevention)

Every component is fine-tuned to work right out of the box, but highly customizable if you want to dive deeper.

Out-of-the-Box Security

  • TLS encryption with Let’s Encrypt
  • Optional SSL cert mounting
  • Firewall and brute-force protection
  • SpamAssassin-style filtering
  • Authenticated SMTP with SASL

Fully Scripted Installation

Managing users, setting up aliases, configuring DKIM? All of that is handled with easy scripts like:

1
2
3
./setup.sh email add john@yourdomain.com
./setup.sh alias add hello@yourdomain.com john@yourdomain.com
./setup.sh config dkim

Simple, right?

Dockerized Deployment

Everything runs in containers, meaning:

  • Minimal host dependencies
  • Easy updates
  • Isolation and portability
  • Easy backup/restore

Why docker-mailserver is a Game Changer

Comparisons with Traditional Mail Servers

Featuredocker-mailserverTraditional Setup
Ease of Setup✅ Easy CLI setup❌ Manual configs
TLS/DKIM/SPF Support✅ Pre-configured❌ Manual setup
Resource Isolation✅ Dockerized❌ Host-dependent
Update Process✅ Docker pull❌ Complex upgrade
Portability✅ High❌ Low

Hassle-Free Admin Experience

From adding users to setting up complex filters, everything is done with scripts. There’s no need to manually edit Postfix or Dovecot configs – unless you want to.

Privacy and Control Over Your Mail

Self-hosting gives you peace of mind that your emails aren’t being scanned or monetized. docker-mailserver lets you own your infrastructure.


Architecture Overview

System Components

Here’s how it all fits together:

  • Postfix: Handles sending and receiving mails
  • Dovecot: Manages mailbox storage and retrieval
  • Rspamd: Scans for spam
  • ClamAV: Catches malware
  • OpenDKIM: Ensures your mail is verifiable
  • Fail2Ban: Keeps brute-force bots away

Docker Compose Integration

Sample docker-compose.yml for quick start:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: '3.8'

services:
  mail:
    image: docker.io/mailserver/docker-mailserver:latest
    hostname: mail
    domainname: yourdomain.com
    container_name: mailserver
    env_file: mailserver.env
    volumes:
      - ./data:/var/mail
      - ./config:/tmp/docker-mailserver/
    ports:
      - "25:25"
      - "587:587"
      - "993:993"
    restart: always

Mail Flow Diagram (Explained)

  1. Mail arrives via SMTP (port 25 or 587)
  2. Filtered by Rspamd and ClamAV
  3. Stored by Dovecot in /var/mail
  4. Retrieved securely by clients via IMAP or POP3

How to Add Users and Manage Mailboxes

Managing users is simplified with setup.sh, which is included in the repository. Here are some of the most common commands:

✅ Add a New Mail User

1
./setup.sh email add john@example.com

✅ Change a User Password

1
./setup.sh email update john@example.com

✅ Create an Alias

1
./setup.sh alias add info@example.com john@example.com

✅ Remove a User

1
./setup.sh email del john@example.com

These scripts eliminate complex configurations and make day-to-day operations extremely admin-friendly.


Advanced Features You’ll Love

🔒 Two-Factor Authentication (2FA)

docker-mailserver supports SASL authentication mechanisms and can be integrated with 2FA systems for added security.

📚 LDAP and Active Directory Support

You can configure the server to use LDAP or AD for centralized user management – perfect for larger teams or organizations.

🗂️ Automatic TLS via Let’s Encrypt

Zero-configuration SSL with Let’s Encrypt. Just mount your certs or let the system handle it.

📜 Logs & Monitoring

Integrated with Docker logging mechanisms, you can monitor your mail flow using standard Docker tools or external services like ELK Stack or Promtail + Grafana.


Community & Documentation

One of the best things about docker-mailserver is its strong documentation and active community.

The documentation is thorough, versioned, and constantly maintained – whether you’re a beginner or a sysadmin, everything is explained clearly.


Real-World Use Cases

  • Freelancers and Small Teams: Own your brand domain and email without paying monthly fees to third-party services.
  • Privacy Enthusiasts: Host your mail on your terms, with no tracking or surveillance.
  • Startups: Custom domains, secure email, and no vendor lock-in.
  • Developers & Sysadmins: Easily script, backup, and automate your entire mail flow.

Final Thoughts: Is docker-mailserver Worth It?

If you’ve ever wanted full control over your mail system without pulling your hair out, docker-mailserver is your answer.

It’s modern, secure, and incredibly flexible. Whether you’re a dev who wants a reliable inbox or a sysadmin tired of managing clunky mail stacks, this project will save you time, money, and frustration.

🧠 Pro Tip: Combine it with tools like Traefik, Watchtower, and GitOps workflows to supercharge your self-hosted infrastructure.


Useful Resources


Conclusion

docker-mailserver empowers you to take back control of your inbox. With Docker simplicity, enterprise-level features, and robust community support, it’s more than just a mail server — it’s a self-hosted email revolution.

So, whether you’re launching a SaaS or just want to say goodbye to Gmail snooping — spin up docker-mailserver today and start sending secure, self-hosted email in minutes.


📨 Still using Gmail for your domain? It’s time to level up. Try docker-mailserver and own your emails — completely.

This post is licensed under CC BY 4.0 by the author.