Sign inSign up

dimtoolsinc/haproxy-docker

By dimtoolsinc

•Updated almost 7 years ago

HAProxy build with logs to stdout and stderr

Image
0

4.6K

dimtoolsinc/haproxy-docker repository overview

⁠HAProxy docker setup with logs

⁠Description

Setup is based on popular solution which you can easily google except for having both stdout and stderr outputs to handle errors separately if necessary

⁠Dockerfile

FROM haproxy:1.8-alpine

RUN set -exo pipefail \
    && apk add --no-cache \
        rsyslog \
    && apk del syslog-ng \
    && mkdir -p /etc/rsyslog.d \
    && touch /var/log/haproxy.log \
    && ln -sf /dev/stdout /var/log/haproxy.log \
    && ln -sf /dev/stderr /var/log/haproxy-error.log

COPY entrypoint.sh /
COPY rsyslog.conf /etc/rsyslog.d/

ENTRYPOINT ["/entrypoint.sh"]

CMD ["-f", "/usr/local/etc/haproxy/haproxy.cfg"]

⁠Contents of entrypoint.sh
#!/bin/sh

set -o errexit
set -o nounset

readonly RSYSLOG_PID="/var/run/rsyslogd.pid"

main() {
  start_rsyslogd
  start_lb "$@"
}

start_rsyslogd() {
  rm -f $RSYSLOG_PID
  rsyslogd
}

start_lb() {
  exec haproxy -W -db "$@"
}

main "$@"
⁠Rsyslog configuration
# Loads the imudp into rsyslog address space
# and activates it.
# IMUDP provides the ability to receive syslog
# messages via UDP.
$ModLoad imudp

# Address to listen for syslog messages to be
# received.
$UDPServerAddress 0.0.0.0

# Port to listen for the messages
$UDPServerRun 514

# Take the messages of any priority sent to the
# local0 facility (which we reference in the haproxy
# configuration) and send to the haproxy.log
# file.
local0.* -/var/log/haproxy.log
local1.* -/var/log/haproxy-error.log

# Discard the rest
& ~

⁠Useful info

⁠HAProxy log levels

HAProxy has 8 log levels ordered ascending: debug,notice,info,warning,err,crit,alert,emerg. Choosing log level you choose to show this particular log level and above, e.g. choosing alert, you'll see only alert and emerg messages.

There's no official match of events of particular messages to log level, but approximately we have next:

  • debug and notice are mostly used for internal events and non-important messages
  • info is commonly used for backend and frontend status messages and http log
  • warning and above log levels are used for internal errors, misconfiguration errors/warnings and critical things that usually lead to haproxy termination.

⁠Example of haproxy.cfg to test image locally

global
                maxconn                   2046
                log                       /dev/log       local0  debug
                log                       /dev/log       local1  alert

defaults
                log                       global

frontend        http
                bind                      :80
                default_backend           backend_default

backend         backend_default
                server                    local-server localhost:8080
⁠Docker-compose setup for testing purposes (place haproxy.cfg in the same folder before using)
version: '2'
services:
  haproxy:
    image: dimtoolsinc/haproxy-docker:1.8-alpine
    volumes:
      - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
    ports:
      - 80:80
    restart: on-failure

Tag summary

Content type

Image

Digest

Size

10.8 MB

Last updated

almost 7 years ago

docker pull dimtoolsinc/haproxy-docker:2.1-alpine