The official HAProxy docker image does not really offer an out-of-the-box way to get to HAProxy’s logs other than sending it to a remote log server. Sending log messages to stdout/stderr so you can view the logs with docker logs
does not appear to be possible with HAProxy.
UPDATE for HAProxy 1.9 and newer
HAProxy has been updated to handle container environments better, see here.
HAProxy 1.8 and older
Exposing /dev/log on docker command line
To get access to the logs, without having to set up a service to receive them, you can choose to grant the container read-write access to the host’s /dev/log
.
docker run -v /dev/log:/dev/log:rw haproxy
Then, make sure you set logging towards /dev/log
in haproxy.cfg
, like so:
global
log /dev/log local0
log /dev/log local1 notice
Exposing /dev/log in docker-compose YAML
In your docker-compose YAML, you can add the volume for /dev/log
as follows:
services:
haproxy:
image: haproxy:alpine
volumes:
- /dev/log:/dev/log:rw
Accessing the logs
With the above examples, the HAProxy logs should now be available on your host machine, simply run journalctl -f
there to see them pass by.
There is, of course, a probability that I missed a way to get to the logs other than sending them to a remote syslog service, but my droplet at Digital Ocean is only so large, and I intend to stay within my budget… Please let me know in the comments below if there is a better way to get to the logs.