DEV Community

Rajat Saxena
Rajat Saxena

Posted on

Debugging HAProxy containers

HAProxy is a popular solution for load balancing and reverse proxy needs. So I will cut to the chase and show you how you can get more insights into your HAProxy container.

In this guide, I am assuming the you are running the offical HAProxy image.

In order to debug your HAProxy container you need to have this program socat installed on your HAProxy container. Using this program you can have insights related to the running instance of HAProxy inside the container.

In your Dockerfile, add the following line to install socat into your container.

RUN apt-get update && apt-get install -y socat && rm -rf /var/lib/apt/lists/*
Enter fullscreen mode Exit fullscreen mode

Now build and start your container normally. Once started, log into the container by issuing the following command.

docker exec -it <haproxy_container_id> sh
Enter fullscreen mode Exit fullscreen mode

After you are logged into the container, you can start the socat program in interactive mode like this.

socat /var/run/haproxy.sock stdio

prompt
Enter fullscreen mode Exit fullscreen mode

Now you can issue commands like show acl, show info, show errors, show env etc., to get more information about the running process. You can head over to this document to see the full list of available commands.

I hope someone will find this quick guide useful. Thanks for reading and check me out on YouTube as I love sharing more development related tips.

Top comments (0)