Tool to add a healthcheck for "FROM SCRATCH" docker images.
./healthchecker -port 3000 -path /healthcheck
./healthchecker -h
Since the image is a "FROM SCRATCH" image, you can just build your image from the healthchecker image :
# main application build
FROM golang:1.21.5 as builder
WORKDIR /build
COPY ./go.* ./
COPY ./ ./
RUN CGO_ENABLED=0 go build -o ./bin/main ./
FROM ermineaweb/healthchecker:latest
WORKDIR /app
COPY --from=builder /build/bin/main ./main
# you can surcharge the healthcheck
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
CMD [ "/app/healthchecker", "-port", "3000", "-path", "/healthcheck" ]
ENTRYPOINT ["./main"]
docker build -t healthchecker:latest .
Then in the dockerfile add these lines :
WORKDIR /app
COPY --from=healthchecker:latest /build/bin/healthchecker ./healthchecker
Add to the dockerfile these lines :
WORKDIR /app
COPY --from=ermineaweb/healthchecker:latest /build/bin/healthchecker ./healthchecker