Healthcheck functionality for Golang Docker images built from scratch.
Original source: https://medium.com/google-cloud/dockerfile-go-healthchecks-k8s-9a87d5c5b4cb
This is useful to add healthcheck in Golang docker images created from scratch.
Note: This project is designed for docker containers (Linux) only.
Project provides an installation script.
curl -sfL https://raw.githubusercontent.com/hibare/go-docker-healthcheck/main/install.sh | sh -s -- -d -b /usr/local/bin
This will install healthcheck in /usr/local/bin
Installation script provides an way to verify checksum signature before running artifact checksum validation. This is an optional step in installation script.
To run signature verification during installation, supply additional -v
argument.
curl -sfL https://raw.githubusercontent.com/hibare/go-docker-healthcheck/main/install.sh | sh -s -- -d -v -b /usr/local/bin
Fetch source code asset from Github release. Compile into a binary.
FROM golang:1.17.0-alpine AS base
# Build golang healthcheck binary
FROM base AS healthcheck
RUN curl -sfL https://raw.githubusercontent.com/hibare/go-docker-healthcheck/main/install.sh | sh -s -- -d -b /usr/local/bin
Copy binary into final stage.
COPY --from=healthcheck /usr/local/bin/healthcheck /bin/healthcheck
Add healthcheck command to docker. Replace the URL in healthcheck with actual application healthcheck URL.
HEALTHCHECK \
--interval=30s \
--timeout=3s \
CMD ["healthcheck", "--url", "http://localhost:5000/ping/"]
A working example can be found here.