Wednesday, 30 December 2015

Logging and the haproxy docker container

So you have configured and built and/or run your configuration file in the haproxy image as per https://hub.docker.com/_/haproxy/.

To repeat the steps are :

1. Create a haproxy.cfg file in a local directory
2. Create a Dockerfile in same directory containing

FROM haproxy:1.5
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

3. Build image with  above docker file using

docker build -t myhaproxy .

4. Check that your image with your configuration is in your image list using

docker images

5. Run your docker image....

docker run -d --name my-running-haproxy my-haproxy

Note that you could also mount the volume with the configuration.

But once its running how do you know what the problem is if something goes wrong? How do you access the logs?

Haproxy logs to syslog, so we would need to build our own version of haproxy with a underlying system with syslog configuration changes.

Or we could do this:


1. Change the configuration in haproxy.cfg to log to /dev/log and rebuild your image.

global
log /dev/log local2


2. When we run our haproxy run with -v /dev/log:/dev/log like this:

docker run -d --name my-running-haproxy -v /dev/log:/dev/log my-haproxy

3. See what is happening in your "host" syslog (/var/log/syslog)

References:
1. https://hub.docker.com/_/haproxy/
2. https://github.com/dockerfile/haproxy/issues/3