Deploy Load Balancer (HAProxy) with

This guide helps you to deploy a Load Balancer (HAProxy) service in a Docker container using the D2C platform. It might be helpful for beginners as well as for advanced developers.

Denis Zaripov

Product manager

Why Docker?

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Containers isolate software from its surroundings, for example, differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.

Please, check out the original Docker post about containers for a better understanding of all the benefits of the technology.


I’m going to start with a project which already has a deployed application service. If you missed that guide, check out our guides for starting the runtime you need. In my case, it is a project with a Python app deployed on three hosts.

Creating HAProxy service

At first, you need to open a service you want to balance and click “+Add load balancer“. 

Creating HAProxy service. Mode

By default, for a HAProxy service D2C creates a public domain like: [servicename-lb]-[www].[accountID].[at] So, for a start it’s better to use HTTP or TCP mode. You can change the mode to HTTPS and add your domain after the service is deployed. We will talk about it below.

Creating HAProxy service. Ports

Access from the Internet is enabled for HAProxy by default. You can disable access from the Internet while creating or editing the service.

Creating HAProxy service. Select hosts

The one thing you need to understand at this step is that HAProxy has enabled access from the Internet by default. 80 and 443 ports should be free at a host which you want to use for deploying HAProxy. If D2C manages a host from scratch (using supported cloud providers, not the own one) the busy ports are shown on a host card:

After successful deployment your project should look like:

Since Python application was deployed using D2C’s hello world test application we can check if Load balancing works or not:

Maintaining HAProxy service. Actions and settings

Let’s open HAProxy and see what settings and actions does it have.

Basic actions

  • Update HAProxy. This action sends a request to update service for the latest available version.
  • Restart. Restarts a container
  • Stop. Stops a container
  • Move. You can move the service to any of your projects. Click on the drop-down icon to choose an existing project or create a new one
  • Destroy. Destroy all the containers of the service. Also, can be run with Force. Click on the drop down icon to destroy with force.

Edit settings

Like any other service, HAProxy has standard blocks as: Service settings, Persistent data volumes, Ports, Custom configs
However, the most important thing is Configure services.

At this block, you can choose what domains to use, change the mode and config of HAProxy. Click on the “Generate new config” button to make changes. 
You might find helpful our previous articles about configuring HAProxy (Part one and Part Two).

The actions and behaviour are almost the same as configuring NGINX. The different are:

  • HAProxy can serve only one service (NGINX can serve any amount of services)
  • HAProxy has Sticky sessions mode. It can reduce the number of connections, and this is one of the ways to allow WebSockets work on multiple hosts. When you turn it on a user connects to the same host all the time:

Maintaining HAProxy service. Logs

System (deploy) logs

You can find System log at the HAProxy service page. You can filter it by date and show only errors or info messages. 
The line which has ellipsis marks in the end can be opened with a mouse click. 

Container logs

You can find container logs at a container page. Click on the container card
Scroll down to the log block and click “Show
You’ll see application logs. Here you can filter it by date and show only errors. 

What next?

Check out our previous guides if you missed: