Below is a minimal, reproducible Dockerfile that builds HAProxy 2.8.10 from source, links it against OpenSSL 3.x (whatever the distro provides), and installs the two Lua libraries you asked for:
• lua-cjson (fast JSON encoder/decoder)
• OpenSSL/LuaSec bindings (so Lua scripts can do TLS)
The image is based on Alpine 3.19 (small footprint, recent OpenSSL 3.x), but the same pattern works on Debian/Ubuntu if you prefer.
# ---------- build stage ----------
FROM alpine:3.19 AS builder
# 1. Install build dependencies
RUN apk add --no-cache \
build-base \
linux-headers \
pcre2-dev \
readline-dev \
zlib-dev \
openssl-dev \
openssl-libs-static \
lua5.3-dev \
git \
curl \
make \
cmake
# 2. Build HAProxy 2.8.10
ARG HAPROXY_VERSION=2.8.10
WORKDIR /usr/src
RUN curl -fsSL "https://www.haproxy.org/download/2.8/src/haproxy-${HAPROXY_VERSION}.tar.gz" | tar xz
WORKDIR /usr/src/haproxy-${HAPROXY_VERSION}
# Build flags: enable Lua, PCRE2, OpenSSL, Prometheus exporter, etc.
RUN make -j$(nproc) \
TARGET=linux-musl \
USE_LUA=1 \
LUA_LIB=/usr/lib/lua5.3 \
LUA_INC=/usr/include/lua5.3 \
USE_OPENSSL=1 \
USE_PCRE2=1 \
USE_ZLIB=1 \
USE_PROMEX=1 \
SSL_LIB=/usr/lib \
SSL_INC=/usr/include \
EXTRA_OBJS="contrib/prometheus-exporter/service-prometheus.o"
RUN make install PREFIX=/usr/local
# 3. Build/install Lua libraries
WORKDIR /usr/src
# lua-cjson
RUN git clone --depth=1 https://github.com/mpx/lua-cjson.git && \
cd lua-cjson && \
make && \
make install LUA_VERSION=5.3 PREFIX=/usr/local
# luaossl (OpenSSL bindings for Lua)
RUN git clone --depth=1 https://github.com/wahern/luaossl.git && \
cd luaossl && \
make && \
make install PREFIX=/usr/local
# ---------- runtime stage ----------
FROM alpine:3.19
RUN apk add --no-cache \
ca-certificates \
pcre2 \
zlib \
readline \
lua5.3-libs \
openssl \
libssl3
# Copy HAProxy binary + default config dir
COPY --from=builder /usr/local/sbin/haproxy /usr/local/sbin/haproxy
COPY --from=builder /usr/local/lib/lua /usr/local/lib/lua
COPY --from=builder /usr/local/share/lua /usr/local/share/lua
# Create haproxy user & working dir
RUN addgroup -S haproxy && adduser -S -D -H -h /var/lib/haproxy -s /sbin/nologin -G haproxy haproxy
# Default minimal config (override at runtime)
COPY <<EOF /usr/local/etc/haproxy/haproxy.cfg
global
lua-load /usr/local/lib/lua/5.3/cjson.so
lua-load /usr/local/lib/lua/5.3/ssl.so
defaults
mode http
timeout connect 5s
timeout client 50s
timeout server 50s
frontend web
bind *:80
default_backend app
backend app
server s1 127.0.0.1:8080
EOF
EXPOSE 80 8404
USER haproxy
ENTRYPOINT ["haproxy", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]
How to build & run:
docker build -t haproxy:2.8.10-lua .
docker run --rm -p 80:80 -p 8404:8404 haproxy:2.8.10-lua
Notes & tweaks
• If you need a different Lua version, change lua5.3-dev/lua5.3-libs to lua5.4-* and adjust LUA_VERSION.
• To add more Lua rocks, install luarocks in the builder stage and run luarocks install <rock>.