Install a mail server on Linux in 10 minutes – with docker, docker-compose, and mailcow

Did you ever want to have a complete, easy, and fast tutorial on how to install and set up a mail server on Linux that can be done in 10 minutes? You don’t want to rely on expensive all-in-one solutions but instead, use only proven open-source applications?

Here you will learn step-by-step how to install and set up all necessary applications to have a fully-featured mail server. And trust me, you can do it in about 10 minutes!


You can use this tutorial once you have installed the Linux server. In my example, I used the distribution Ubuntu 18.04 LTS, but you can use this tutorial on almost every Linux distribution that supports docker. Note, that the installation of docker can be slightly different.

1. Why is a mail server set up more complex?

Mail servers are more complex than most other applications to install and set up on Linux. This is because there is no single “mail server” application, as a mail server is a bunch of several applications and services. This is based on what you expect from a fully-featured mail server and what open-source applications can offer. You probably need an MTA (mail transfer agent) which is responsible for mail transport. But you may also need the ability to collect your emails via IMAP and POP3, a webmail application, an antispam solution or a database.

Of course, there is an open-source solution for all of these tasks. They are well proven because they are existing since the earliest beginning of the internet. But there are several options for services and applications you could use and they all need to interact with each other. The configuration is all done via static config files for each service. Therefore, it can be very complex to set up a fully-featured mail server on Linux.

But don’t worry! There are also solutions to make it more easy, smooth and seamless.

2. How can we simplify this approach?

There are three main components we will use to simplify the installation, configuration, and management of these different applications.

Docker: This is a product that allows running applications in separate containers on the host system. The main difference between a virtual machine and a container is, that the container system doesn’t come with the overhead of a full operating system. It only has the main component that is needed to run the application. Therefore, a container engine like docker is a very efficient way to run multiple applications in an isolated environment.

Docker Compose: Managing and configuring Docker containers can be difficult and complex. Docker Compose can manage multiple Docker containers. Because it manages this via a single configuration file that can run and configure multiple docker containers with a single command.

Mailcow: This is a collection of all necessary applications to create a fully-featured mail server. It uses all open-source projects like postfix, MySQL, dovecot, etc., and runs them in docker containers. It will manage the containers via docker-compose so that you don’t need to struggle with config files yourself.

3. Install docker on Ubuntu 18.04 LTS

First, we need to install docker on our Linux server. If you have trouble or want to use another distro/operating system, you can also refer to the official docker documentation:

1. (Optional) Remove old docker installation

It is recommended, to first uninstall old docker installations. If you already have docker set up and running correctly or never used it before, you can skip this step.

$ sudo apt remove docker docker-engine containerd runc
2. Install docker repository
$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
$ sudo apt update
3. Install docker
$ sudo apt-get install docker-ce docker-ce-cli
4. Check if docker was installed successfully

If everything was successful you can test docker, with this simple command

$ sudo docker run hello-world

4. Install docker-compose on Ubuntu 18.04 LTS

1. Check latest stable release

Docker-compose has no installation package for apt. You may check the latest stable release version first on the official website

2. Download docker-compose

Download the latest version (in this case it is 1.25.5, this may change whenever you read this tutorial!)

$ sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
3. Make directory executable
$ sudo chmod +x /usr/local/bin/docker-compose
4. Check if docker-compose is working correctly

If everything was successful you can test docker-compose with this command.

$ sudo docker-compose --version

5. Install mailcow

1. Clone mailcow into the /opt folder

$ cd /opt
$ sudo git clone
$ cd mailcow-dockerized

2. Generate your configuration file and follow the steps below.

$ sudo ./

3. Enter your mailserver FQDN (this is your mailserver hostname, not your domain name)

4. Select your timezone

5.1. (Optional) Insert custom SSL certificate

If you start “mailcow” it will automatically generate and request a letsencrypt certificate for your domains. If you don’t want that, but instead use your own certificate you need to modify the mailserver.conf and change the line to:


Afterward, you can insert your own SSL certificate and replace the files cert.pem and key.pem in the “/opt/mailcow-dockerized/data/assets/ssl” directory

Refer to:

5.2. Start mailcow

You can start your mail server on Linux with the following command, but you need to be inside the “/opt/mailcow-dockerized” directory to execute the docker-compose.yml file

$ sudo docker-compose up -d

6. Configure mailcow

When all services are started successfully, you can now login to the admin dashboard and configure your domain, mailboxes, aliases, etc.

The admin dashboard can be accessed by https://<fqdn>

The default user and password are: admin moohoo

mail cow admin dashboard example

7. Set up your domain(s)

You need to set up your domain first at “Configuration -> Mail Setup -> Domains

example of domain setup

8. Set up your mailboxes

If you want to configure your mailboxes, you can add them at “Configuration -> Mail Setup -> Mailboxes

example of mailbox setup

9. What else needs to be done?

Now, I hope if everything worked fine, you got your mail server installed up and running! There might be other tasks to do in order to make it functional for a production environment. It now really depends on your special needs and infrastructure and can’t be generally suggested. Here are some ideas, what else you might need to do.

  • Add additional domains
  • Add mailbox aliases
  • Configure your public MX record
  • Add SPF record and set up DKIM and DMARC entry
  • Send and receive test-emails