Application Health Check with Golang and Multi-Stage Docker Build

Dockerfile to build and run the healthcheck app

FROM golang:alpine as builderRUN apk update && apk add git && apk add ca-certificatesADD . /build/WORKDIR /buildRUN go get -d -vRUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main .FROM scratchCOPY --from=builder /build/main /app/COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/WORKDIR /appCMD ["./main"]

Build a Go application

docker build -t healthcheck .
docker run --rm healthcheck
Output of building and executing the Docker image
7.42 MB for the healthcheck Docker image

Code the final Healthcheck

docker run --rm -p 3001:3001 healthcheckcurl localhost:3001/healthcheck
output of curl localhost:3001/healthcheck

Software Architect

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store