How to configure a test mail server with the Docker? – Cooking notes [EN]

Today I would like to show you a standard working scenario from a developer perspective. During development we have to verify if our solution (code) is working properly, that’s why we need to have resources. It’s good when you have already created VM’s, installed apps etc… in some cases you just need to do it by yourself. My goal was to prepare some fake mail server for integration tests with different TLS versions. It may sound easy, but have in mind that you would like to customize it in the future.

You should start with the research, thanks to that you can answer questions like what already exists, what is already the most common solution, if yes is it free etc. After that, you are able to take the next steps. Test mail servers are not very obvious, the first idea is to use Gmail, if you are ok with that it’s great! But did you consider limitations of Gmail, are you aware that you can’t send more than 1000 mail per 24h? When you are thinking about CI (Continous Integration) you can’t allow for such limitations. Moreover, you should be able to handle and maintain such services, they need to be reliable!

Some time ago, I’ve started switching to the delegation for such resources, even when they are paid. But in this case, I’ve decided to create a test mail server with the Docker! It’s one of the cheapest solutions, you just need to have a working PC.

Ok, don’t waste more time and take a look at the recipe for how to „cook” the problem.

How to setup it on your own server?

So the first thing is to have OS (Linux or Windows) – in our case we use Linux server created on Azure portal.  All configuration is based on https://mailu.io/compose/setup.html with some modifications. It’s a great set to create a test mail server, we will be able to have an admin panel, webmail and even antivirus! You can remove some parts from the configuration later 😉

So after OS installation, you need to install docker (in our case for Ubuntu):

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

and

– docker-compose https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-ubuntu-16-04

If you are using apt-get install method, make sure that you have the latest updates and install new versions of components. You can verify it with a command:
docker –version, then compare it with the latest versions on the Github.

Download a config package, and upload it to your VM. You can use e.g. scp command or ftp client.

mailu-nginx-custom-config

Use tar command to extract the folder in the server e.g.:

tar xzvf mailu-nginx-custom-config.zip

Have you noticed that this package is only ~8KB? All configuration to set up mail server, configure network etc. in so small package. Rest of our effort will be taken care of by the Docker.

What was changed in the config file?

  • so I’ve changed ssl_protocol for nginx
  • I’ve added more cyphers to the  ssl_ciphers to have TLS1.0 availability

Change config files

Now it’s time to change some files to setup your config. Open .env file

  • BIND_ADDRESS4=0.0.0.0, describes on what port your server would be available in this case it would connect to the VM IP address so all ports will be available globally if you want to test it in the local network change it to 127.0.0.1
  • DOMAIN – provide main mail domain address usually with mail in the beginning
  • HOSTNAMES – provide a valid domain name
  • Website website domain


For testing purpose, you can enable admin and webmail options.

To specify TLS version

I had to test mail server with different TLS versions to make sure that client wouldn’t have a problem with our software while connecting to different servers.

Open nginx/conf/tls.conf, then in ssl_protocols specify what TLS protocols you would like to use e.g:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

If you change anything in ngins/* files you need to run sudo docker-compose build, before running sudo docker-compose up, otherwise configuration wouldn’t be updated.

Run containers:

Then you just need to run the following command in the main (where docker-compose.yml is located) folder:

sudo docker-compose up -d

This command will build and run all services in detach mode. Be patient, it may need some time, it will download all the necessary images and run containers. Then you can verify if docker was set up correctly by writing:

sudo docker ps

And see some started containers.

Create an admin account

To create an admin account you need to invoke below command, where

  • root – is the name of the user
  • example.net – your domain
  • password – password for the account

docker-compose run –rm admin python manage.py admin root example.net password

That’s all! Even after OS restarts your docker should put up our images.

Remove unnecessary ports

If you’ve tested everything you can remove some ports and disable admin and webmail.

To do this simple use:
sudo docker-compose down

It will stop all services from the docker-compose.yml, then modify your config files. If you want to remove 80 port remove this line from docker-compose.yml

– „$BIND_ADDRESS4:80:80”mailu-nginx-custom-config

It’s universal!

You can use this solution to create any additional resources. I knew some things about Docker but I didn’t have time to read a book about it, and then start implementation of the solution. I’ve used learning by doing method and it’s very common during software development, and I was able to achieve my goal pretty quickly – prepare test servers.
Thanks to the Docker you are able to isolate your own configuration to the containers and don’t mess with OS. Moreover, you can create more than 1 docker container on the same machine and use additional ports to have more than 1 test server, isn’t it brilliant?  😎

ZOSTAW ODPOWIEDŹ

Please enter your comment!
Please enter your name here

Loading Facebook Comments ...