Simple healthcheck for web app containers
The healthcheck will report as healthy if the HTTP request is successful and the status of the HTTP requests is not in
the range of 400-599
. Provide the healthcheck URL as the first argument to the binary.
Check out the web-test-container Dockerfile for a usage example.
The
simple-web-healthcheck
binary currently has a size of around 3.5 MB. I'll probably rewrite it inhyper
or another lower level HTTP client, to reduce the size further.
Add as a step to your multistage container build:
# Build healthcheck
FROM rust:1.87-bookworm AS healthcheck-builder
RUN cargo install simple-web-healthcheck
# Rest of your build...
FROM gcr.io/distroless/cc-debian12
COPY --from=healthcheck-builder /usr/local/cargo/bin/simple-web-healthcheck /healthcheck
# Copy your app here
HEALTHCHECK --interval=10s --timeout=1s CMD ["/healthcheck", "http://127.0.0.1:8080"]