Sign inSign up

mastertinner/healthcheck

By mastertinner

Updated about 5 years ago

A minimalistic base Docker image with built in health checking

Image
0

647

mastertinner/healthcheck repository overview

Healthcheck

Build Status Build Status Docker Build

A base image for minimal Docker images. It is an extension of scratch that contains a built in HTTP health check and encourages non-privileged execution. This image only adds about 2.8M to scratch and is intended for running HTTP services written in languages that compile to a binary format (e.g. Go or Rust).

Advantages

  • Your binary will be executed using the non privileged app user
  • A HTTP health check is run every 30 seconds

Usage

Rust
FROM rust:1 AS builder
WORKDIR /usr/src/myapp
COPY . .
RUN cargo build --release

FROM mastertinner/healthcheck:latest
WORKDIR /usr/myapp
COPY --from=builder /usr/src/app/target/release/myapp .
EXPOSE 8080
ENTRYPOINT ["./myapp"]

You can add the following lines to your Cargo.toml file to further minimize the size of the final image:

[profile.release]
opt-level = "z"
lto = true
Go
FROM golang:1 AS builder
WORKDIR /usr/src/myapp
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -a -installsuffix cgo -o bin/myapp ./cmd/myapp

FROM healthcheck:latest
WORKDIR /usr/myapp
COPY --from=builder /usr/src/myapp/myapp .
EXPOSE 8080
ENTRYPOINT ["./myapp"]
Customize

You can set the following environment variables in your container to customize the health check:

  • PORT: The port your app is listening on. Defaults to 8080.
  • HEALTHCHECK_PATH: The health check path of your app. Defaults to /.

Tag summary

Content type

Image

Digest

Size

1.2 MB

Last updated

about 5 years ago

docker pull mastertinner/healthcheck