How to set up your own Docker mail server step by step
You can set up a dedicated mail server in just a few steps and thereby gain maximum control over your digital messaging traffic. Setup with Docker and its ready-to-use stack “Docker mail server” is very popular. What are the requirements? And how exactly can a mail server be set up?
- What hardware is needed for your Docker mail server?
- Step by step tutorial: Setting up a mail server with Docker
Set up your own professional email server in the blink of an eye. You benefit from large and expandable storage space, your own domain, automatic encryption as well as calendar and office functions or email archiving. IONOS also offers the highest security standards in ISO-certified data centers.
What hardware is needed for your Docker mail server?
You need the appropriate hardware to operate your own mail server. The dimensions will be determined by the performance required, such as how many messages are sent per day and how many people use the server at a time. The average size of the messages exchanged is also relevant. Further power should be planned for additional services such as a backup system or content scanner (protection against spam, phishing, etc.). You will also need a static IP address to ensure smooth interaction with other mail servers.
The capacities required will play a decisive role when choosing how to set up your mail server. A simple Start-Setup is sufficient for a handful of mails per day, while a heavily used mail server in the business sector should have enough RAM, CPU and storage space.
Don’t forget to plan resources for the underlying operating system, whether you have Windows or Linux.
We have summarized three mail server scenarios and assigned a suitable IONOS server plan for each.
Mail server scenario
Suitable IONOS plan
Simple home server with little traffic
2 vCores, 4 GB RAM, 60 GB hard disk space
Mail server for a small company with up to 1,000 daily mails
4 vCores, 8 GB RAM, 100 GB hard disk space
Enterprise mail server with over 50,000 daily mails
8 vCores, 16 GB RAM, 500 GB hard disk space
A dedicated server from IONOS gives you access to enterprise hardware which is reserved exclusively for you. In contrast, the “vServer” and “Cloud Server” models are based on virtualized resources which are shared with other customers — without performance losses.
Step by step tutorial: Setting up a mail server with Docker
There are various options for setting up a mail server. In the following tutorial, we have selected a server based on the Docker container “Docker mail server”. The streamlined open source container (MIT license) provides a ready-to-use stack for setting up your own email server. All the important components are included, such as an SMTP server, IMAP or POP3 server, antispam, and antivirus software or an LDAP registry service.
If you want to work with a Docker image like “Docker mail server”, you will need to install the container platform first. You can find out more on this in our extensive Docker tutorial.
Continue reading the following sections to learn exactly how the “Docker mail server” setup works.
Step 1: Get Docker image
docker pull mailserver/docker-mailserver
Enter the following command to install it from the GitHub registry:
docker pull ghcr.io/docker-mailserver/docker-mailserver:edge
Step 2: Configure docker-compose.yml
The next step is to prepare the “Docker mail server” container to start. For this, a registry for the mail server must be set up, such as “mail server Docker”. A new YAML file named docker-compose.yml should then be created in this registry and the following content for a basic configuration of the mail server can be added:
# example.com should be replaced with the own domain for the mail server:
domain name: example.com
# Path should be adjusted accordingly:
# If letsencrypt for SSL/TLS certificate is used (otherwise adapt)
- NET_ADMIN # For Fail2Ban to work
See the official manuals of Docker mail server on GitHub for a detailed list of possible settings for the mail server.
Step 3: Release ports
The three ports 25, 465, and 587 are entered in the YAML file. These are the classic SMTP server ports, which must also be released in the server’s firewall settings for smooth operation. The exact procedure depends on the system and provider — IONOS customers (vServer, Cloud Server, Dedicated Server) can conveniently complete the port release with the Cloud Panel. The required steps are as follows:
- Log in to the login page of the Cloud Panel with your personal customer data.
- Go to the “Server & Cloud” section.
- Select the rented server hardware where you want to set up your mail server.
- Click “Network” and then “Firewall Policies” in the left side menu.
- Add the three TCP ports “25”, “465”, and “587” one after the other using “Add Rule”.
Step 4: Apply host name to DNS settings
In the next step, make sure that the server’s DNS service uses an MX record for the hostname configured in Step 2 (here: “mail server”). Add an SPF TXT record with the hostname and the value “v=spf1 mx ~all”.
As an IONOS customer, you can also change your server’s DNS settings using the Cloud Panel as follows:
- Log in to the Cloud Panel login page if you are no longer logged in there.
- Click on the entry “Domains & SSL”.
- Click on the gear icon next to the domain entry where you set up your mail server and select “DNS”.
- You can now use the “Add Record” button to add two entries for MX and SPF TXT.
Finally, press “Reset domain” in the top menu to apply the changes. Confirm the adjustments you have made and click “Reset now”.
Do you want to store your electronic messages and have legal security and be GoBD compliant? Use the Email archiving from IONOS to archive selected inboxes legally and prevent any possible tampering!
Step 5: Generate DKIM keys
Create a DKIM entry to increase the mail server’s security level. This encryption technique can later be used to digitally sign messages. Use the setup.sh script file located in the Docker mail server registry to generate the key pair. Carry out the following command there:
./setup.sh config dkim
Add the generated entry — found in the file docker-data/dms/config/opendkim/keys/example.com/mail.txt — to the DNS records as another TXT entry so that receiving mail servers can retrieve the public key. The output looks like this:
mail._domainkey IN TXT ( "v=DKIM1; h=sha256; k=rsa; "
"iqq3bD/BVlwKRp5gH6TEYEmx8EBJUuDxrJhkWRUk2VDl1fqhVBy8A9O7Ah+85nMrlOHIFsTaYo9o6+cDJ6t1i6G1gu+bZD0d3/3bqGLPBQV9LyEL1Rona5V7TJBGg099NQkTz1IwIDAQAB" ) ; ----- DKIM key mail for example.com
The encryption of mail communication with SSL/TLS is just as important as DKIM entries. Docker mail server developers recommend using letsencrypt for activation, but you can also use certificates which you have already purchased. Detailed setup instructions can be found in the mail server’s official GitHub documentation.
Step 6: Start server and create first address
Start the configured mail server directly from the registry with the following command:
The first email address can be set up within two minutes. Use the following command for this, adjusting the domain, username, and password accordingly:
./setup.sh email add user@domain password
Additional profiles can be created at any time allowing you to set up your mail server exactly as you wish.
Email hosting services tailored to your needs
Increase your credibility with an email address that matches your business!