aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Include a healthcheck binary for use in a docker compose environment

Open rgl opened this issue 1 year ago • 3 comments

in order to have a healthcheck in docker compose we need a command that returns a 0 exit code.

we either need a dashboard sub-command (e.g. dotnet /app/Aspire.Dashboard.dll readyz) or an http client (e.g. curl) binary available inside the container.

a healthcheck endpoint should also be available, so we can use this in other places, like k8s.

for example, in this hypothetical docker compose file, I'm using curl (but a better approach would be to implement something equivalent of this example, but as a dashboard sub-command, e.g., dotnet /app/Aspire.Dashboard.dll readyz):

# see https://github.com/compose-spec/compose-spec/blob/master/spec.md
# see https://github.com/opencontainers/image-spec/blob/master/annotations.md
services:
  aspire-dashboard:
    # see https://mcr.microsoft.com/product/dotnet/nightly/aspire-dashboard/about
    # see https://github.com/dotnet/dotnet-docker/issues/5128
    # see https://github.com/dotnet/aspire/issues/2248#issuecomment-1947902486
    # see https://github.com/dotnet/aspire/tree/main/src/Aspire.Dashboard
    image: mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.0.0-preview.5
    environment:
      - DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS=true
    ports:
      # web ui.
      - 18888:18888
      # otlp grpc.
      #- 18889:18889
    healthcheck:
      test: ["CMD", "curl", "--silent", "--fail-with-body", "--max-time", "5", "http://localhost:18888/healthz/ready"]
      interval: 15s
      timeout: 5s
      retries: 2
    restart: on-failure

rgl avatar Apr 04 '24 17:04 rgl

Why does it need to be a binary? Why not an endpoint?

davidfowl avatar Apr 07 '24 06:04 davidfowl

docker (and docker compose) only support healthchecks by calling a binary (e.g. as the healthcheck.test command displayed above). Have a look at the Dockerfile HEALTHCHECK instruction documentation.

rgl avatar Apr 07 '24 12:04 rgl

What's wrong with the example where they append || exit 1

HEALTHCHECK --interval=5m --timeout=3s \
  [CMD](https://docs.docker.com/reference/dockerfile/#cmd) curl -f http://localhost/ || exit 1

jeff-techstension avatar May 19 '24 12:05 jeff-techstension

What's wrong with the example where they append || exit 1

HEALTHCHECK --interval=5m --timeout=3s \
  [CMD](https://docs.docker.com/reference/dockerfile/#cmd) curl -f http://localhost/ || exit 1

curl or any similar command isn't included in the aspire docker image. It also looks like the image doesn't include any shells that could help.

matburton avatar Dec 03 '24 11:12 matburton