haproxy-alpine

HAProxy Alpine Docker Image

HAProxy社区版Docker镜像,基于Alpine Linux构建,提供高性能负载均衡与反向代理功能,适用于构建轻量级、高可用的Web服务或应用集群。

19 次收藏下载次数: 0状态:社区镜像维护者:haproxytech仓库类型:镜像最近更新:
下载命令
点击查看

Supported tags and respective Dockerfile links

  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/3.5/Dockerfile
  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/3.4/Dockerfile
  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/3.3/Dockerfile
  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/3.2/Dockerfile
  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/3.0/Dockerfile
  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/2.8/Dockerfile
  • https://github.com/haproxytech/haproxy-docker-alpine/blob/main/2.6/Dockerfile

Quick reference

  • Where to get help:
    HAProxy mailing list, https://slack.haproxy.org/ or #haproxy on Libera.chat

  • Where to file issues:
    https://github.com/haproxytech/haproxy-docker-alpine/issues

  • Maintained by:
    https://github.com/haproxytech

  • Supported architectures: (https://github.com/docker-library/official-images#architectures-other-than-amd64)
    linux/amd64, linux/arm64. linux/arm/v6, linux/arm/v7, linux/386

  • Image updates:
    https://github.com/haproxytech/haproxy-docker-alpine/commits/main, https://github.com/haproxytech/haproxy-docker-alpine

  • Source of this description:
    https://github.com/haproxytech/haproxy-docker-alpine/blob/main/README.md

What is HAProxy?

HAProxy is the fastest and most widely used open-source load *** and application delivery controller. Written in C, it has a reputation for efficient use of both processor and memory. It can proxy at either layer 4 (TCP) or layer 7 (HTTP) and has additional features for inspecting, routing and modifying HTTP messages.

It comes bundled with a web UI, called the HAProxy Stats page, that you can use to monitor error rates, the volume of traffic and latency. Features can be toggled on by updating a single configuration file, which provides a syntax for defining routing rules, rate limiting, access controls, and more.

Other features include:

  • SSL/TLS termination
  • Gzip compression
  • Health checking
  • HTTP/2
  • gRPC support
  • Lua scripting
  • DNS service discovery
  • Automatic retries of failed connections
  • Verbose logging

How to use this image

This image is being shipped with a trivial sample configuration and for any real life use it should be configured according to the https://docs.haproxy.org/ and https://github.com/haproxy/haproxy/tree/master/examples. We will now show how to override shipped haproxy.cfg with one of your own.

Create a Dockerfile

dockerfile
FROM haproxytech/haproxy-alpine:3.0
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

Build the container

console
$ docker build -t my-haproxy .

Test the configuration file

console
$ docker run -it --rm my-haproxy haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg

Run the container

console
$ docker run -d --name my-running-haproxy my-haproxy

You will also need to publish the ports your HAProxy is listening on to the host by specifying the -p option, for example -p 8080:80 to publish port 8080 from the container host to port 80 in the container.

Use volume for configuration persistency

console
$ docker run -d --name my-running-haproxy -v /path/to/etc/haproxy:/usr/local/etc/haproxy:ro haproxytech/haproxy-alpine:3.0

Note that your host's /path/to/etc/haproxy folder should be populated with a file named haproxy.cfg as well as any other accompanying files local to /etc/haproxy.

Reloading config

To be able to reload HAProxy configuration, you can send SIGUSR2 to the container:

console
$ docker kill -s USR2 my-running-haproxy

Enable Data Plane API

To use Data Plane API it is easiest to use s6-tagged images which all have Data Plane API running by default.

Despite the tag name, the s6-tagged images are no longer supervised by s6-overlay: they run https://github.com/haproxytech/gopherd as PID 1, which starts HAProxy and Data Plane API and restarts either one if it exits. On first start a random password replaces the shipped admin placeholder in /usr/local/etc/haproxy/dataplaneapi.yml. HAProxy is started with two thirds of the container's memory limit (-m) and Data Plane API with one third (GOMEMLIMIT).

In these images SIGUSR2 reloads HAProxy, and both SIGTERM and SIGUSR1 stop the container. By default HAProxy then stops immediately. Set USE_SIGUSR1 to any non-empty value to make it finish serving existing connections first. That lasts until hard-stop-after in your configuration expires, or without it until Docker's stop timeout, so raise that as well:

console
$ docker run -d -e USE_SIGUSR1=1 --stop-timeout 60 haproxytech/haproxy-alpine:s6-3.4

The services can be managed from inside the container with gopherd status, gopherd restart haproxy, gopherd signal haproxy USR2 and so on. For tooling and bind-mounted configuration written for the s6 images, s6-svc and s6-svstat are still present, including at their old /command and /package/admin/s6/command paths, and translate to gopherd: s6-svc -2 /run/s6-rc/servicedirs/haproxy still reloads HAProxy. The -o, -O, -Q and -x flags ask for supervision changes gopherd cannot make at runtime, so they exit 100 with an explanation instead. New scripts should call gopherd directly.

Running Data Plane API images read-only

The s6-tagged images can run with a read-only root filesystem (--read-only) when the directories they write to are volumes. With the shipped /usr/local/etc/haproxy/dataplaneapi.yml those are two trees:

  • /usr/local/etc/haproxy holds haproxy.cfg and dataplaneapi.yml, which Data Plane API rewrites, and the directories it stores uploaded files in: maps (maps_dir), ssl (ssl_certs_dir), general (general_storage_dir) and spoe (spoe_dir).
  • /usr/local/var/lib/dataplaneapi holds Data Plane API's internal state in storage (dataplane_storage_dir), along with its transactions and configuration backups.

/run (the gopherd and HAProxy sockets) and /tmp (the SPOE transaction directory) must be writable as well, but need not persist, so a tmpfs is enough:

console
$ docker run -d --name my-running-haproxy --read-only \
    --tmpfs /run --tmpfs /tmp \
    -v haproxy-config:/usr/local/etc/haproxy \
    -v haproxy-dataplaneapi:/usr/local/var/lib/dataplaneapi \
    -p 80:80 -p 443:443 -p 5555:5555 \
    haproxytech/haproxy-alpine:s6-3.4

Docker fills an empty named volume with the image's files on first use, so the container starts from the default configuration. The generated admin password, configuration changes, maps, certificates and SPOE files are then kept when the container is recreated. To read the password:

console
$ docker exec my-running-haproxy grep password: /usr/local/etc/haproxy/dataplaneapi.yml

A bind-mounted host directory is not filled in, and without haproxy.cfg and dataplaneapi.yml neither service can start, so copy the defaults out of the image first:

console
$ docker create --name haproxy-defaults haproxytech/haproxy-alpine:s6-3.4
$ docker cp haproxy-defaults:/usr/local/etc/haproxy/. /srv/haproxy/config/
$ docker cp haproxy-defaults:/usr/local/var/lib/dataplaneapi/. /srv/haproxy/dataplaneapi/
$ docker rm haproxy-defaults

Then use -v /srv/haproxy/config:/usr/local/etc/haproxy -v /srv/haproxy/dataplaneapi:/usr/local/var/lib/dataplaneapi in place of the named volumes. If the configuration directory is not writable, the container exits at start instead of serving Data Plane API with the shipped admin password.

License

View https://raw.githubusercontent.com/haproxy/haproxy/master/LICENSE for the software contained in this image.

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 haproxy-alpine 镜像标签

docker pull docker.xuanyuan.run/haproxytech/haproxy-alpine:<标签>

DockerHub 原生拉取命令

docker pull haproxytech/haproxy-alpine:<标签>
专业版 · 高速稳定拉取镜像
50GB 仅 ¥8/年
高速镜像下载在线技术支持专业版保障服务可用付费会员免广告