A dedicated mail server gives you full control over your digital com­mu­ni­ca­tions. This guide focuses on setting up your own mail server using Docker. It covers every­thing from re­quire­ments and security rec­om­men­da­tions to a complete step-by-step tutorial. With Docker’s ready-to-use container stacks, like Docker mail server, deploying a secure and scalable mail solution has never been easier.

What is a Docker mail server?

A Docker mail server is a self-hosted email solution deployed in con­tain­ers using Docker. It handles sending, receiving, and storing email while enabling full control over data privacy, security policies, and system con­fig­u­ra­tion. Compared to third-party providers like Gmail or Outlook, a Docker mail server puts you in charge of your in­fra­struc­ture — ideal for de­vel­op­ers, privacy-conscious users, and small busi­ness­es.

Why use Docker for a mail server?

Using Docker to host your mail server has several key ad­van­tages:

  • Isolation and security: Docker con­tain­ers isolate the mail server, reducing the risk of system-wide com­pro­mise and improving security.

  • Porta­bil­i­ty: Docker con­tain­ers can be easily moved across en­vi­ron­ments, ensuring con­sis­tent setup between local and cloud servers.

  • Sim­pli­fied de­ploy­ment: Docker provides pre-con­fig­ured stacks, stream­lin­ing the setup process and elim­i­nat­ing the need for manual con­fig­u­ra­tion.

  • Scal­a­bil­i­ty: Easily scale Docker con­tain­ers to ac­com­mo­date growing email traffic and changing resource re­quire­ments.

  • Version control: Specify Docker image versions to prevent com­pat­i­bil­i­ty issues and enable easier rollback if needed.

  • Con­sis­ten­cy across en­vi­ron­ments: Docker ensures con­sis­tent con­fig­u­ra­tions and setups across de­vel­op­ment, testing, and pro­duc­tion en­vi­ron­ments.

An email server that's secure, powerful, and reliable
  • Highest security standards
  • Automatic en­cryp­tion with SSL/TLS
  • ISO-27001 certified and geo-redundant data centers
  • IMAP & SMTP

What are the re­quire­ments for running a Docker mail server?

Note

This guide is for tech­ni­cal­ly skilled users familiar with Linux and Docker who want a private and flexible email in­fra­struc­ture. It’s es­pe­cial­ly relevant for de­vel­op­ers, IT ad­min­is­tra­tors, and small busi­ness­es.

To host your own Docker mail server, you’ll need suf­fi­cient hardware resources depending on the expected email traffic. A static IPv4 address is essential for smooth mail server in­ter­ac­tions. Ad­di­tion­al­ly, ensure proper DNS con­fig­u­ra­tion, including MX, SPF, DKIM, and DMARC records. IPv6 support is also in­creas­ing­ly important for better com­pat­i­bil­i­ty and email rep­u­ta­tion.

  • Docker image: docker-mailserver/docker-mailserver:v13.2+
  • Email protocols: SMTP (Ports 25, 587, 465), IMAPS (993), POP3S (995)
  • Security standards: TLS 1.3, DKIM, SPF, DMARC, DNSSEC (if supported)
  • Host OS: Ubuntu 22.04 LTS, Debian 12, or equiv­a­lent stable Linux dis­tri­b­u­tions
Tip

You can simplify the entire process using Docker mail server, a popular open-source stack main­tained by the community. It includes Postfix, Dovecot, rspamd, ClamAV, and optional LDAP in­te­gra­tion — all in one container.

What should be con­sid­ered when setting up a Docker mail server?

Security con­fig­u­ra­tions overview

To protect your mail server, make sure to con­sis­tent­ly apply security settings, including the following:

  • Use up-to-date TLS cer­tifi­cates (at least TLS 1.2, ideally TLS 1.3)
  • Set up and enforce SPF, DKIM, and DMARC policies
  • Implement rate limiting and au­then­ti­ca­tion via SASL
  • Enable encrypted con­nec­tions for IMAP/POP3 and SMTP
  • Set up logging with tools like rsyslog and struc­tured log rotation
Note

Even with con­tainer­ized setups using Docker, an in­de­pen­dent security con­fig­u­ra­tion is essential. Docker sim­pli­fies in­stal­la­tion but does not replace system hardening through firewalls, strict user rights, logging (e.g., via rsyslog), and regular system updates.

General rec­om­men­da­tions for setup

Setting up a Docker mail server requires technical expertise and thorough security con­fig­u­ra­tion. Here are some key points to focus on:

  • Choosing an ap­pro­pri­ate Docker image and mail server stack (e.g. docker-mailserv­er/docker-mailserv­er)
  • Con­fig­ur­ing DNS records (MX, SPF, DKIM, DMARC)
  • Securing the Docker host (firewall, Fail2Ban, en­cryp­tion)
  • Choosing the right ad­min­is­tra­tive and mon­i­tor­ing tools
  • Regular updates and backups (including Docker image updates)
  • Con­fig­ur­ing reverse DNS entries and IPv6 support
  • Complying with legal re­quire­ments (e.g., GDPR, legally compliant email archiving)

What hardware is required?

To run your own Docker mail server, ap­pro­pri­ate hardware is essential. The necessary per­for­mance depends on various factors, including how many emails are sent daily and how many people will be using the server. Docker con­tain­ers are light­weight, but you still need to consider RAM, CPU, and storage. Ad­di­tion­al per­for­mance may be required for extra services like backup systems or content scanners (e.g., spam or phishing pro­tec­tion). You will also need a static IPv4 address for smooth in­ter­ac­tion with other mail servers — dynamic IPs can cause issues with email delivery.

Tip

Want to give your Docker mail server a personal, pro­fes­sion­al touch? A custom domain is essential for this. Register your personal domain with IONOS today and get an SSL/TLS cer­tifi­cate for your mail server on top!

When looking for a suitable en­vi­ron­ment for your Docker mail server, it’s important to consider what ca­pac­i­ties need to be covered. A simple setup can handle a handful of emails per day, while a heavily used business mail server requires sub­stan­tial RAM, CPU, and storage.

Note

Whether Windows or Linux: Don’t forget to account for the resources needed for the un­der­ly­ing operating system.

Mail server scenario Hardware Rec­om­mend­ed IONOS plan
Simple home server with low traffic 2 vCores, 8 GB RAM, 240 GB SSD Virtual Server Cloud L from IONOS
Mail server for a small business (up to 1,000 emails/day) 8 vCores, 16 GB RAM, 480 GB SSD Virtual Server Cloud XL from IONOS
En­ter­prise mail server (over 50,000 emails/day) 6 vCores, 32 GB RAM, 2 x 480 GB SSD RAID Dedicated AMD Server from IONOS
Note

With a Dedicated Server, you gain access to en­ter­prise hardware ex­clu­sive­ly reserved for you. In contrast, vServers and Cloud Servers use vir­tu­al­ized resources shared with other customers — without any per­for­mance loss.

How to set up a Docker mail server step by step

In this tutorial, we’ve chosen the popular Docker container docker-mailserv­er.

This light­weight, open-source container (MIT License) offers a modular, ready-to-use stack for setting up your own mail server. It in­te­grates all the essential com­po­nents, such as an SMTP server, IMAP or POP3 server, optional spam and antivirus pro­tec­tion, and, if needed, an LDAP directory service.

Step 1: Get the Docker image

You can get the latest docker-mailserv­er image from the official Docker Hub directory or the official GitHub repos­i­to­ry.

The rec­om­mend­ed approach is to pull a stable release, such as v13.2, rather than using the :latest or :edge tags.

Run the following command to pull the image:

docker pull mailserver/docker-mailserver:v13.2 
# or: 
docker pull ghcr.io/docker-mailserver/docker-mailserver:v13.2
bash

Step 2: Configure docker-compose.yml

Next, you’ll need to configure docker-compose.yml to define the necessary services and volumes for your Docker container. Here’s an example con­fig­u­ra­tion for your mail server:

version: '3.8' 
 
services: 
  mailserver: 
    image: docker.io/mailserver/docker-mailserver:v13.2 
    container_name: mailserver 
    hostname: mail-server 
    domainname: example.com 
    ports: 
      - "25:25" 
      - "587:587" 
      - "465:465" 
    volumes: 
      - ./docker-data/dms/mail-data/:/var/mail/ 
      - ./docker-data/dms/mail-state/:/var/mail-state/ 
      - ./docker-data/dms/mail-logs/:/var/log/mail/ 
      - ./docker-data/dms/config/:/tmp/docker-mailserver/ 
      - ./docker-data/nginx-proxy/certs/:/etc/letsencrypt/ 
      - /etc/localtime:/etc/localtime:ro 
    environment: 
      - ENABLE_FAIL2BAN=1 
      - SSL_TYPE=letsencrypt 
      - PERMIT_DOCKER=network 
      - ONE_DIR=1 
      - ENABLE_POSTGREY=0 
      - ENABLE_CLAMAV=0 
      - ENABLE_SPAMASSASSIN=0 
      - SPOOF_PROTECTION=0 
    cap_add: 
      - NET_ADMIN 
      - SYS_PTRACE
yaml

This con­fig­u­ra­tion ensures that your Docker container uses the correct ports for SMTP (25), IMAPS (993), and SMTP Sub­mis­sion (587), and that volumes are properly mapped for per­sis­tent data storage. Ad­di­tion­al­ly, security features like Fail2Ban and Let’s Encrypt SSL are enabled.

Note

You can find a complete list of con­fig­urable options in the Docker Mailserv­er official doc­u­men­ta­tion.

Step 3: Open required ports

In your docker-compose.yml file, you’ll notice the SMTP server ports are listed (25, 465, and 587). These must also be opened in your server’s firewall to ensure smooth email traffic.

If you’re using a service like IONOS for hosting, you can easily open these ports via the Cloud Panel:

  1. Log in to the IONOS Cloud Panel.
  2. Go to the “Server & Cloud section.”
  3. Select the server you are using to host the Docker mail server.
  4. In the left-hand menu, click “Network” then “Firewall Policies.”
  5. Add firewall rules for TCP ports 25, 465, and 587.
Image: IONOS Cloud Panel: Add Firewall Rule
IONOS Cloud Panel: Add firewall rule

Step 4: Configure DNS settings

In the next step, you need to ensure that the DNS service for your domain is correctly con­fig­ured:

  • MX Record: Points to the mail server (e.g., mail.example.com) that you defined under hostname and domainname in your docker-compose.yml.
  • SPF Record: A TXT record for the domain (not for the hostname!), e.g., v=spf1 mx ~all.
Note

~all stands for “Softfail” – al­ter­na­tive­ly, you can use -all if you prefer a stricter policy.

How to configure DNS in IONOS Cloud Panel:

  1. Log in to your IONOS Cloud Panel.
  2. Go to “Domains & SSL.”
  3. Find your domain and click the settings icon.
  4. Select “DNS.”
  5. Add the following records:
  • MX Record: Target = mail.example.com, Priority = 10
  • TXT Record: Type = TXT, Value = v=spf1 mx ~all
Image: IONOS Cloud Panel: Add DNS Record
IONOS Cloud Panel: Add DNS Record

Finally, click on “Reset Domain” in the top menu to reload the DNS con­fig­u­ra­tion and apply the changes. Confirm your entries by clicking “Reset Now” – this will only affect the updated DNS records, not the domain itself.

Tip

Want to securely archive your business emails in com­pli­ance with Canadian laws? With IONOS Email Archiving you can au­to­mat­i­cal­ly archive selected mailboxes in a tamper-proof, legally compliant format.

Step 5: Generate DKIM keys

To increase the security of your mail server, you need to generate a DKIM (Do­mainKeys Iden­ti­fied Mail) record for your domain. This technique allows emails to be digitally signed, so receiving mail servers can verify their au­then­tic­i­ty.

Use the provided setup.sh script in the docker-mailserver directory:

./setup.sh config dkim
bash

The generated public key will be saved in the following file (assuming the volume was correctly mounted):

docker-data/dms/config/opendkim/keys/example.com/mail.txt
swift

Open the file and copy its contents to create a TXT record in your domain’s DNS settings. The DNS record might look like this:

mail._domainkey.example.com. IN TXT ( 
    "v=DKIM1; h=sha256; k=rsa; " 
    "p=MIIBIjANBgkqhkiG9w0BAQEFAAOC...continuedPublicKey...IDAQAB" 
)
java
  • mail is the selector and can be named as you prefer (e.g., default, key2025, etc.).
  • If your DNS provider limits the length to 255 char­ac­ters per string, you will need to split the key (as shown in the example).
  • Make sure the record type is TXT and it applies to the full domain mail._domainkey.example.com.
Note

In addition to DKIM, you should also set up an SPF record and a DMARC record to ensure full pro­tec­tion against email spoofing.

Step 6: Start the server and create your first address

Start the con­fig­ured mail server directly from the project directory with the following command:

docker-compose up -d
bash

These in­struc­tions will help you securely and ef­fi­cient­ly set up both modern container-based and tra­di­tion­al mail server en­vi­ron­ments.

An email server that's secure, powerful, and reliable
  • Highest security standards
  • Automatic en­cryp­tion with SSL/TLS
  • ISO-27001 certified and geo-redundant data centers
  • IMAP & SMTP
Go to Main Menu