How to Install mailcow: dockerized on Debian 13
Install the Docker-based mailcow mail server suite on Debian 13 or 12, with the DNS records, ports and first-login steps you need.
mailcow: dockerized is a complete, open-source mail server suite: Postfix, Dovecot, Rspamd, ClamAV, SOGo webmail and a web interface for managing domains and mailboxes, all running as Docker containers. This guide installs it on Debian 13 and takes you as far as the first login and the DNS records your domain needs. The same steps work on Debian 12.
Early mailcow tutorials used a shell installer that configured packages directly on Debian 7 and 8. Those Debian releases are long out of support, and the mailcow documentation today covers mailcow: dockerized, which is what this guide installs.
Requirements
| Resource | Minimum |
|---|---|
| CPU | 1 GHz, x86_64 or ARM64 |
| RAM | 6 GiB plus 1 GiB swap (8 GiB recommended for 5 to 10 users) |
| Disk | 20 GiB, not counting mail storage |
| Virtualization | Bare metal or full virtualization such as KVM; OpenVZ, Virtuozzo and LXC are not supported |
You also need:
- A fresh Debian 13 (or 12) server with root access and no other mail or web server on it.
- A fully qualified hostname for the mail server, for example
mail.example.com, and access to the DNS zone of your domain. - Inbound TCP ports 25, 465, 587, 143, 993, 110, 995, 4190, 80 and 443. Many providers block outbound port 25 on new accounts; ask your provider to lift the block, because without it you cannot deliver mail.
- The ability to set the reverse DNS (PTR) record of the server's IP address in your hosting control panel.
On a small server you can lower memory use by setting SKIP_CLAMD=y (no antivirus) and SKIP_FTS=y (no full-text search) in mailcow.conf after the configuration step.
Step 1: Create the DNS records
Create these records before you install, so that the automatic TLS certificate request succeeds on first start. Replace the address with your server's IP:
mail IN A 203.0.113.10
@ IN MX 10 mail.example.com.
autodiscover IN CNAME mail.example.com.
autoconfig IN CNAME mail.example.com.
@ IN TXT "v=spf1 mx a -all"
Then set the PTR record of 203.0.113.10 to mail.example.com. Receiving servers reject or junk mail from hosts whose reverse DNS does not match. If the server has an IPv6 address, add an AAAA record and an IPv6 PTR as well. DKIM and DMARC records follow after installation.
Step 2: Prepare the system
Run the commands in this guide as root (su - or sudo -i). Update the system and install the tools mailcow's scripts use:
apt update
apt upgrade -y
apt install -y git openssl curl gawk coreutils grep jq
Make sure nothing is listening on the mail and web ports:
ss -tlpn | grep -E -w '25|80|110|143|443|465|587|993|995|4190'
The command should print nothing. A Debian system that was upgraded from 12 to 13 may have Exim installed, which occupies port 25; remove it:
apt purge -y 'exim4*'
mailcow's two-factor login depends on a correct clock. Check that time synchronisation is active:
timedatectl status
If System clock synchronized says no, run timedatectl set-ntp true.
Step 3: Install Docker and Docker Compose
mailcow needs a current Docker Engine and Docker Compose 2.0 or later. The project advises using Docker's own packages rather than the ones in the Debian archive:
curl -sSL https://get.docker.com/ | CHANNEL=stable sh
systemctl enable --now docker
Install the Compose plugin if the script did not already, and check both versions:
apt install -y docker-compose-plugin
docker --version
docker compose version
Step 4: Download mailcow and generate the configuration
mailcow expects a umask of 0022. Set it, then clone the repository into /opt:
umask 0022
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
Generate the configuration file. The script asks for the mail server's hostname (enter the full name, mail.example.com) and your time zone:
./generate_config.sh
The result is mailcow.conf in the same directory. Review it if you want to change ports or disable components:
nano mailcow.conf
If your network uses an MTU other than 1500, which is common on OpenStack-based clouds, set the matching value for the mailcow network in docker-compose.yml before starting.
Step 5: Start mailcow
docker compose pull
docker compose up -d
The first pull downloads several gigabytes of images. When the command returns, check that the containers are up:
docker compose ps
Give the stack a few minutes on first start: the database is initialised and a Let's Encrypt certificate is requested for the hostname.
Step 6: Log in and add your domain
Open https://mail.example.com/admin and log in with the default account: user admin, password moohoo. Change that password immediately in the administrator settings and consider enabling two-factor authentication.
Then, in the mail configuration section of the interface:
- Add your domain (
example.com). - Create a mailbox, for example
deploy@example.com. - Generate a DKIM key for the domain and publish the value shown as a TXT record named
dkim._domainkey. - Add a DMARC record, starting with a monitoring policy and tightening it once reports look clean:
_dmarc IN TXT "v=DMARC1; p=none; rua=mailto:postmaster@example.com"
Mailbox users reach webmail (SOGo) and their own settings through https://mail.example.com. Mail clients use IMAP on port 993 and SMTP submission on port 587 or 465 with the full e-mail address as the user name.
Firewall notes
Docker publishes container ports through its own iptables rules, so rules in the INPUT chain, including typical ufw rules, do not filter traffic to mailcow. If you need to restrict access, add rules to the DOCKER-USER chain, which survives Docker restarts. mailcow also needs outbound access for DNS, signature and rule updates, and SMTP on port 25.
Updating and backing up
mailcow ships its own update script. Check for a new version, then apply it:
cd /opt/mailcow-dockerized
./update.sh --check
./update.sh
Read the release notes before major updates. A rollback is only possible together with a database backup, because an older version cannot use a newer database schema. All data lives in Docker volumes and survives container recreation; back those volumes up regularly, either with the backup script in the helper-scripts directory or with your own volume-level backups, and keep a copy off the server.
Frequently asked questions
Can I run a website on the same server?
mailcow's own Nginx container occupies ports 80 and 443. To share the server you have to move mailcow's web ports with the HTTP_BIND, HTTP_PORT and HTTPS_PORT settings in mailcow.conf and put a reverse proxy in front. A dedicated server or VPS for mail is simpler and easier to keep off blocklists.
Why does my mail land in spam?
Check, in this order: the PTR record matches the hostname, SPF and DKIM pass, a DMARC record exists, and the IP address is not on a blocklist. A new IP address has no reputation, so start with low volumes. The mailcow interface includes a DNS check for each domain that shows which records are missing or wrong.
What if my server has no IPv6?
mailcow enables IPv6 inside its Docker network by default. On a host without IPv6 connectivity, follow the project's instructions for disabling IPv6 in the mailcow network, otherwise some lookups and deliveries are attempted over a path that does not exist.
Does mailcow run on Ubuntu or AlmaLinux too?
Yes. The project lists Debian 11 to 13, Ubuntu 22.04 and later, AlmaLinux 8 and 9 and Rocky Linux 9 as fully compatible. Only the package manager commands for the prerequisites and Docker differ; see the mailcow documentation for each.