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

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

  1. Hi, your tutorial is extremely efficient !

    I have a question : I want to add another domain (main) to let’s encrypt in this composer. How can I manage to do that ?

  2. Thank you for opening our eyes to this perfect solution. I also liked the explanatory video on youtube. It is based on ubuntu and I would like to know if you have a procedure for a VPS server based on Centos 7.4. Thanks again .

  3. Thanks for the tutorial! I am getting some problems after running “sudo docker-compose up -d”. It is giving me many errors: for example –

    ERROR: for unbound-mailcow Cannot start service unbound-mailcow: error while creating mount source path ‘/opt/mailcow-dockerized/data/conf/unbound/unbound.conf’: mkdir /opt/mailcow-dockerized: read-only file system

    ERROR: for watchdog-mailcow Cannot start service watchdog-mailcow: error while creating mount source path ‘/opt/mailcow-dockerized/data/assets/ssl’: mkdir /opt/mailcow-dockerized: read-only file system

    Plus a few more with the ” read-only file system” issue. Any Ideas as to how this can be corrected would be greatly appreciated?
    Many thanks

    • I would check if the mount point is really read-only. This command should list all read-only mountpoints in your filesystem. If /opt is read-only you would need to remount it as rw. If not there probably is an issue with permissions on this folder.
      awk '$4~/(^|,)ro($|,)/' /proc/mounts

  4. Hi,
    Love your tutorial, but I have a problem. I can send emails from this server to a gmail account, but when I try to do the same the other way round, my mail server does not recieve the email. What can I do?

  5. Hi it would be very helpful if you can make video how to make work mailcow nginx (for mail) and apache2 (for website) in the same server.

  6. Hello I don’t know about lot Docker and want to install mail cow but thinking about future if I will loss docker containers then I can loss everything. Please May you tell me about it

  7. Hi,
    Thank you very much for the tutorial! But I have a problem. I have set all the dns records. I can now receive emails but I cannot send. Could you advice me where to look for the possible issue based on priority?

  8. Hello Christian and thank you, your tutorials are really useful and most importantly easy.

    I have a question regarding thr rDNS. I’ve installed mailcow on my home server (no VPS, just an old pc) and I can’t get to understand where/how to find my reverse DNS.
    I reasearched the whole google but no chance.

  9. Hello Christian:
    I get below error when in login with the created user, their mailbox looks to be disconnected. I was unable to find the resolution for this issue.

    No mailbox selected

    error_outline An error occured while communicating with the mail server

  10. Hi!

    I followed your installation instructions and everything installed very gracefully. Now I have noticed that when loging in the site appears as not being secured by SSL.

    Can you shed some light on this?

  11. Installed everything. created mail box also. but i am getting wrong username and password after creating the users. did for multiple times. but same error . can u help me

  12. Pingback: my weblog
  13. Hello Christian. I have followed and put into practice your tutorial. I used Ubuntu server as a virtual machine on Virtalbox but every time I restart this machine, I can’t access the mail server (ubuntu server). I have to delete the virtual machine each time and reinstall another one. How can I solve my problem?

  14. Hi

    I’ve followed the set up and manage to get to the sogo. I am able to receive emails but not send them – I can send it out from Sogo but the receiving email does not ever receive the email. Do you have any suggestions on why this is happening/how to resolve?

  15. Thanks! its good and Easy way to implement.
    but i have one question that :
    is it fully open source?
    is it request a license?
    is it useful for Enterprise center ?

  16. Dear
    Great blog.

    Regarding firewall rules, are you using ufw and/or external firewall and/or from aws/azure ?
    Will be great if you could add some details about that.

    Best Regards

  17. Hello

    Thank you so much for the guide, it really is helpful and I managed to setup my email server in literally 15-20minutes.

    Only problem I have is I am not able to get the domains certified with SSL certificates. And no, nothing happened when I added 2 domains to mailcow. I am currently able to send and received emails on both domains, but need to bypass the ssl warnings each time I want to log in. As is now, I cannot deploy to other users. Please help??

    Thank you!


Leave a Comment

I accept the Privacy Policy