Log with Docker
When HAProxy Enterprise runs as a Docker container, you can collect logs in the following ways:
Forward logs to 'standard out', allowing you to capture them using a log aggregation tool
Forward logs to a remote Syslog server, which can run in a separate container
Log to standard out
This method publishes logs to stdout, allowing you to offload the collection of logs to an external tool, such as logspout.
-
Place a
log
statement into theglobal
section of your configuration file:use stdout as the address
use format raw for a shortened log format compatible with a variety of tools
use local0 as the facility code
global log stdout format raw local0
-
Add a
log global
statement to adefaults
section to enable the global logging rule in all subsequentlisten
,frontend
, andbackend
sections:defaults log global
-
View logs by querying the HAProxy Enterprise container using the
docker logs
command:$ sudo docker logs hapee
Log to a syslog container
This method allows you to forward logs to a container running a Syslog server, such as Rsyslog.
-
Place a
log
statement into theglobal
section of your configuration file:use the IP address or name of your Syslog container, with an optional port number
use local0 as the facility code
global log rsyslog:514 local0
-
Add a
log global
statement to adefaults
section to enable the global logging rule in all subsequentlisten
,frontend
, andbackend
sections:defaults log global
-
View logs by querying the rsyslog container using the
docker logs
command:$ sudo docker logs rsyslog
HAProxy Enterprise configuration
global
log rsyslog:514 local0
defaults
log global
frontend fe_main
bind :80
default_backend be_main
backend be_main
server web1 web1:8080 check
Docker commands
$ # Create Docker network
$ sudo docker network create -d bridge my-network
$ # Run web server container
$ sudo docker run -d --network my-network --name web1 \
--restart unless-stopped jmalloc/echo-server
$ # Run Rsyslog container
$ sudo docker run -d --network my-network --name rsyslog \
--restart unless-stopped jumanjiman/rsyslog
$ # Run HAProxy Enterprise container
$ sudo docker run -d --network my-network --name hapee \
-p 80:80 -p 443:443 --restart unless-stopped \
-v (pwd):/etc/hapee-2.3 \
hapee-registry.haproxy.com/hapee-business:2.3r1
Next up
Logging Reference