Home > Software engineering >  Docker HealthChecks fail on ASP.Net application
Docker HealthChecks fail on ASP.Net application

Time:10-20

Im trying to dockerize an ASP.NET application, however I am having some issues with the health checks, I have a simple program like

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHealthChecks();

var app = builder.Build();

app.MapGet("/", () => "Hello World!");
app.MapHealthChecks( "/health" );

app.Run();

And when I run it locally, it all works fine and I can see that the healthchecks return healthy, however when I run it in a docker container with the following docker-compose

version: '3.2'

services:
asp-service:
  image: bitnami/dotnet-sdk
  working_dir: /app
  command: "./run.sh"
  volumes:
    - "./:/app:rw"
  ports:
    - 8080:8080
  healthcheck:
    test: curl --fail https://asp-service:8080/health || exit 1
    interval: 30s
    timeout: 30s
    retries: 3

Where run.sh is a simple script which just runs dotnet run I can see the service runs fine, however when I run docker ps I can see the status returns health: unhealthy

CodePudding user response:

There could be one of two issues:

  1. The healthcheck can't resolve the hostname, asp-service. Try pointing the curl command to localhost:8080 instead.
  2. Your service is either insecure and needs to use http instead of https or you need to provide your certificates to the curl command. It's unusual for local services to be secured, so I'm assuming that you didn't mean to use https.
  • Related