Skip to content

Mailcow self-hosted stack — Docker-based mail with batteries included

Install the Mailcow dockerized mail stack, point DNS at it, and understand the trade-offs of a pre-bundled mail platform versus rolling Postfix + Dovecot + Rspamd by hand.

Mailcow is the most-deployed batteries-included self-hosted mail stack — Postfix, Dovecot, Rspamd, SOGo, ClamAV, Nginx, and a web admin all wrapped in docker-compose. This article is the install we run when a client wants self-hosted mail without the per-component plumbing covered in our postfix-install-ubuntu → dovecot-install-imaps → opendkim-signing-postfix chain. The trade: less control, faster bootstrap, a vendor-shaped operational model.

How to verify

A clean box is the right starting point — Mailcow expects to own port 25, 465, 587, 993, 110, 995, 80, and 443.

ss -ltnp | grep -E ':(25|80|110|143|443|465|587|993|995)\b'
which docker docker-compose
docker --version
free -m
df -h /
hostnamectl

You want a box with at least 6 GB RAM, 20 GB disk, a real FQDN with matching forward and reverse DNS, and no other mail/web stack listening on those ports.

What’s happening

Mailcow ships about a dozen Docker containers from one docker-compose.yml:

  • postfix-mailcow — the MTA. Listens on 25/465/587.
  • dovecot-mailcow — the IMAP/POP3/LMTP/Sieve server. Listens on 143/993/110/995/4190.
  • rspamd-mailcow — the spam scoring milter. Web UI at /rspamd.
  • nginx-mailcow — the front-end that terminates TLS for the admin UI and SOGo.
  • php-fpm-mailcow / acme-mailcow — the admin UI runtime and Let’s Encrypt issuance.
  • mysql-mailcow / redis-mailcow — the data stores. Auth, Bayes, sessions.
  • sogo-mailcow — the groupware (calendar, address book, webmail).
  • clamd-mailcow — antivirus.
  • unbound-mailcow — a local DNS resolver, so DNSBL/RBL lookups don’t go through the cloud’s flaky resolver.
  • solr-mailcow (optional) — full-text mail search.

The admin UI handles domains, mailboxes, aliases, SPAM rules, and DKIM key generation. The whole stack persists in data/ directories under the project root — that is your single backup target.

The mental shift from a Postfix-by-hand deploy: configuration is in the admin UI and stored in MySQL, not in flat config files. Override files exist for advanced cases (data/conf/postfix/extra.cf, data/conf/rspamd/local.d/...) but most operators never touch them. The trade-off is real — fewer knobs, but a maintained upgrade path you don’t have to engineer.

The procedure

  1. Prepare the host. Docker, docker-compose-plugin, and the firewall:

    sudo apt update
    sudo apt install -y docker.io docker-compose-plugin git
    sudo systemctl enable --now docker
    sudo ufw allow 25,80,110,143,443,465,587,993,995,4190/tcp
    sudo ufw reload
  2. Clone the repo. Mailcow is distributed as a git repo, not a Docker image you pull:

    cd /opt
    sudo git clone https://github.com/mailcow/mailcow-dockerized
    cd mailcow-dockerized
  3. Generate the config. The script asks for the mail FQDN and writes mailcow.conf:

    sudo ./generate_config.sh
    # Mail server hostname (FQDN): mx1.example.com
    # Timezone: America/Toronto
    # ...

    The script writes mailcow.conf with port mappings, the admin URL, the timezone, and the database root password.

  4. Publish the DNS records. Before starting Mailcow, publish:

    ; A record
    mx1.example.com.    IN A     203.0.113.10
    
    ; MX record
    example.com.        IN MX    10  mx1.example.com.
    
    ; Auto-discover for clients
    autodiscover.example.com.  IN CNAME  mx1.example.com.
    autoconfig.example.com.    IN CNAME  mx1.example.com.
    
    ; SPF
    example.com.        IN TXT   "v=spf1 mx ~all"

    DKIM and DMARC come after Mailcow has generated the keys — step 7.

  5. Pull images and start the stack. First run takes a few minutes — many images, several gigabytes:

    sudo docker compose pull
    sudo docker compose up -d
    sudo docker compose ps

    You should see all containers in Up (healthy) after about 2 minutes. The admin UI is at https://mx1.example.com/ — first login is admin / moohoo and the install script demands a change at first login.

  6. Add the domain and mailboxes via the admin UI. Configuration → Mail Setup → Domains → Add. Then Mailboxes → Add. Each mailbox is local@domain with a quota.

  7. Generate DKIM and publish the record. Configuration → Configuration → ARC/DKIM keys → Add. Pick a selector (sh2026q2), 2048 bit. The UI shows the TXT record to publish; the path of least surprise is dkim._domainkey.example.com (Mailcow defaults to dkim as the selector when you don’t override).

    Then publish DMARC:

    _dmarc.example.com.  IN TXT  "v=DMARC1; p=none; rua=mailto:dmarc@example.com; adkim=r; aspf=r"
  8. Let’s Encrypt and the post-hook. Mailcow’s acme-mailcow container handles ACME against the FQDN you set in mailcow.conf. It runs on a daily timer, renews when needed, and reloads the dependent containers automatically. Confirm:

    sudo docker compose logs acme-mailcow --tail 50
  9. Smoke-test inbound and outbound. Send a probe through SOGo (https://mx1.example.com/SOGo/) or Roundcube. Use port25.com to verify SPF/DKIM/DMARC pass on a single round trip.

When Mailcow is the right choice

  • The client wants self-hosted mail but doesn’t want to staff a per-component operator.
  • The deployment is single-domain or low-multi-tenant (Mailcow scales to ~50-100 domains comfortably; beyond that the admin UI starts to feel cramped).
  • The upgrade rhythm of monthly mailcow.sh update is acceptable.

When Mailcow is the wrong choice

  • The client needs to run a non-standard backend (custom passdb, exotic Sieve scripts, Lua hooks in Rspamd) — Mailcow exposes these only via override files that the next upgrade may stomp on.
  • The deployment is genuinely large (>100k mailboxes); the single-box architecture doesn’t shard cleanly.
  • The client wants ARM or aarch64 hosts — Mailcow’s amd64 image set is more complete than aarch64.

Common pitfalls

  • Port 25 is blocked outbound by the cloud provider — Mailcow runs fine but no mail leaves; this is a provider ticket, not a Mailcow bug.
  • The admin UI is exposed to the internet but admin / moohoo was not changed at first login — automated scanners will find it within hours.
  • A snapshot backup of data/ is taken while MySQL is running — restore is inconsistent. Run mailcow.sh backup (which quiesces MySQL) or stop the stack before snapshotting.
  • The reverse DNS (PTR) is the cloud provider default (ec2-...amazonaws.com) — Gmail and Microsoft drop with 550 5.7.25 rejections. Set the PTR before going live; see bind9-reverse-ptr-for-mail.
  • Upgrades have failed in the past on filesystem-cased differences (Hash vs hash in container names on case-insensitive filesystems); always run mailcow.sh update on the box itself, not over docker compose pull separately.

Stack Harbor stands up Mailcow as the default self-hosted mail platform for clients who don’t have a dedicated mail operator — install scripted, DNS in version-controlled zone data, monthly upgrade window booked, backups verified by restore. If you have a Mailcow that has drifted away from the upstream release for fear of breaking something, that re-baselining work is part of our Managed Operations practice.