Ruchir Bharadwaj
Ruchir Bharadwaj

Reputation: 1272

how to get logs in a haproxy:1.5-alpine Docker container

Building an haproxy container from haproxy:1.5-alpine

(https://github.com/docker-library/haproxy/blob/1848d2933afbefd0e0a068dc7b5a753ab7842e6c/1.5/alpine/Dockerfile)

The haproxy container start fine however how I could achieve detailed haproxy logging and direct it to stdout.

my haproxy config is

global
     log /dev/log  local0
    # log /dev/log  local1 notice
    # chroot /var/lib/haproxy
    # stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    tune.ssl.default-dh-param 2048
    # Default SSL material locations
    #ca-base /etc/ssl/certs
    #crt-base /etc/ssl/private

    ssl-default-bind-options no-sslv3
    ssl-default-bind-ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM
enter code here

defaults
    log global
    mode  http
    option  httplog
    option  dontlognull

    # fixed configuration by Benson
    option  http-keep-alive
    timeout http-keep-alive 5m
    timeout http-request 5s
    timeout connect 300s
    timeout client  300s
    timeout server  300s
    timeout check   300s

    #old configurations causing connection timeouts
    #timeout connect 5000
    #timeout client  50000
    #timeout server  50000

    errorfile 400 /usr/local/etc/haproxy/errors/400.http
    errorfile 403 /usr/local/etc/haproxy/errors/403.http
    errorfile 408 /usr/local/etc/haproxy/errors/408.http
    errorfile 500 /usr/local/etc/haproxy/errors/500.http
    errorfile 502 /usr/local/etc/haproxy/errors/502.http
    errorfile 503 /usr/local/etc/haproxy/errors/503.http
    errorfile 504 /usr/local/etc/haproxy/errors/504.http
    balance roundrobin
    option httpchk

I tried the option of directing logs to stdout via below command in docker entrypoint.sh

"/bin/sh -c /sbin/syslogd -O /dev/stdout"

#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
        set -- haproxy "$@"
fi

if [ "$1" = 'haproxy' ]; then
        # if the user wants "haproxy", let's use "haproxy-systemd-wrapper" instead so we can have proper reloadability implemented by upstream
        /bin/sh -c /sbin/syslogd -O /dev/stdout
        shift # "haproxy"
        set -- "$(which haproxy-systemd-wrapper)" -p /run/haproxy.pid "$@"
fi

exec "$@"

however when I am browsing the apps via haproxy no logs are getting registered, though it serve fine.

I am wondering how could i get the detailed logging via haproxy inside alpine haproxy container

Upvotes: 3

Views: 6864

Answers (2)

takahar tanak
takahar tanak

Reputation: 41

You can use log stdout statement instead of log rsyslogserver:514 . reference: Haproxy get logs from docker container

Upvotes: 0

kim0
kim0

Reputation: 291

You need to pass /dev/log from the host into the container and then read your logs from the host side! The author of haproxy is against logging to stdout (for performance reasons), so there is not much you can do except what I described (or running syslog daemon in another container in the pod)

Upvotes: 3

Related Questions