This image is generic, thus you can obviously re-use it within your non-related EEA projects.
- Debian: Buster
- HAProxy: 1.8
- Expose: 5000
:latestDockerfile - Debian: Buster, HAProxy: 1.8
:1.8-1.8Dockerfile - HAProxy: 1.8.31 Release: 1.8:1.8-1.7Dockerfile - HAProxy: 1.8.30 Release: 1.7:1.8-1.6Dockerfile - HAProxy: 1.8.29 Release: 1.6:1.8-1.5Dockerfile - HAProxy: 1.8.22 Release: 1.5
See older versions
- Install Docker
- Install Docker Compose.
Here is a basic example of a docker-compose.yml file using the eeacms/haproxy docker image:
version: "2"
services:
haproxy:
image: eeacms/haproxy
depends_on:
- webapp
ports:
- "80:5000"
- "1936:1936"
environment:
BACKENDS: "webapp"
DNS_ENABLED: "true"
LOG_LEVEL: "info"
webapp:
image: eeacms/hello
The application can be scaled to use more server instances, with docker-compose scale:
$ docker-compose up -d --scale webapp=4
The results can be checked in a browser, navigating to http://localhost.
By refresing the page multiple times it is noticeable that the IP of the server
that served the page changes, as HAProxy switches between them.
The stats page can be accessed at http://localhost:1936 where you have to log in
using the STATS_AUTH authentication details (default admin:admin).
Note that it may take up to one minute until backends are plugged-in due to the
minimum possible DNS_TTL.
$ docker run --env BACKENDS="192.168.1.5:80 192.168.1.6:80" eeacms/haproxy
Using the BACKENDS variable is a way to quick-start the container.
The servers are written as server_ip:server_listening_port,
separated by spaces (and enclosed in quotes, to avoid issues).
The contents of the variable are evaluated in a python script that writes
the HAProxy configuration file automatically.
If there are multiple DNS records for one or more of your BACKENDS (e.g. when deployed using rancher-compose),
you can use DNS_ENABLED environment variable. This way, haproxy will load-balance
all of your backends instead of only the first entry found:
$ docker run --link=webapp -e BACKENDS="webapp" -e DNS_ENABLED=true eeacms/haproxy
$ docker run -v conf.d/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg eeacms/haproxy:latest
If you edit haproxy.cfg you can reload it without having to restart the container:
$ docker exec <name-of-your-container> reload
Additionally, you can supply your own static haproxy.cfg file by extending the image
FROM eeacms/haproxy:latest
COPY conf.d/haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
RUN apt-get install...
and then run
$ docker build -t your-image-name:your-image-tag path/to/Dockerfile
As HAProxy has close to no purpose by itself, this image should be used in combination with others (for example with Docker Compose).
HAProxy can be configured by modifying the following env variables,
either when running the container or in a docker-compose.yml file.
STATS_PORTThe port to bind statistics to - default1936STATS_AUTHThe authentication details (written asuser:passwordfor the statistics page - defaultadmin:adminFRONTEND_NAMEThe label of the frontend - defaulthttp-frontendFRONTEND_PORTThe port to bind the frontend to - default5000FRONTEND_MODEFrontend mode - defaulthttporBACKENDS_MODEif declaredPROXY_PROTOCOL_ENABLEDThe option to enable or disable accepting proxy protocol (truestands for enabled,falseor anything else for disabled) - defaultfalseCOOKIES_ENABLEDThe option to enable or disable cookie-based sessions (truestands for enabled,falseor anything else for disabled) - defaultfalseCOOKIES_NAMEWill be added on cookie declaration - defaultSRV_IDCOOKIES_PARAMSWill be added on cookie declaration - exampleindirect nocache maxidle 30m maxlife 8hormaxlife 24h- documentation https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-cookieBACKEND_NAMEThe label of the backend - defaulthttp-backendBACKENDSThe list ofserver_ip:server_listening_portto be load-balanced by HAProxy, separated by space - by default it is not setBACKENDS_PORTPort to use when auto-discovering backends, or whenBACKENDSare specified without port - by default80BACKENDS_MODEBackends mode - defaulthttporFRONTEND_MODEif declaredBALANCEThe algorithm used for load-balancing - defaultroundrobinSERVICE_NAMESAn optional prefix for services to be included when discovering services separated by space. - by default it is not setLOGGINGOverride logging ip address:port - default is udp127.0.0.1:514inside containerLOG_LEVELSet haproxy log level, default isnotice( only send important events ). Can be:emerg,alert,crit,err,warning,notice,info,debugDNS_ENABLEDDNS lookup providedBACKENDS. Use this option when your backends are resolved by an internal/external DNS service (e.g. Docker 1.11+, Rancher)DNS_TTLDNS lookup backends everyDNS_TTLminutes. Default1minute.TIMEOUT_CONNECTthe maximum time to wait for a connection attempt to a VPS to succeed. Default5000msTIMEOUT_CLIENTtimeouts apply when the client is expected to acknowledge or send data during the TCP process. Default50000msTIMEOUT_SERVERtimeouts apply when the server is expected to acknowledge or send data during the TCP process. Default50000msHTTPCHKThe HTTP method and uri used to check on the servers health - defaultHEAD /HTTPCHK_HOSTHost Header override on http Health Check - defaultlocalhostINTERparameter sets the interval between two consecutive health checks. If not specified, the default value is2sFAST_INTERparameter sets the interval between two consecutive health checks when the server is any of the transition state (read above): UP - transitionally DOWN or DOWN - transitionally UP. If not set, thenINTERis used.DOWN_INTERparameter sets the interval between two consecutive health checks when the server is in the DOWN state. If not set, thenINTERis used.RISEnumber of consecutive valid health checks before considering the server as UP. Default value is2FALLnumber of consecutive invalid health checks before considering the server as DOWN. Default value is3
By default the logs from haproxy are present in the docker log, by using the rsyslog inside the container (UDP port 514). No access logs are present by default, but this can be changed by setting the log level.
You can change the logging level by providing the LOG_LEVEL environment variable:
docker run -e LOG_LEVEL=info ... eeacms/haproxy
You can override the log output by providing the LOGGING environment variable:
docker run -e LOGGING=logs.example.com:5005 ... eeacms/haproxy
Now make sure that logs.example.com listen on UDP port 5005
The Initial Owner of the Original Code is European Environment Agency (EEA). All Rights Reserved.
The Original Code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.