'dotnet healthcheck endpoint breaks application when running from docker container
We have a dotnet 6 application which contains a health check endpoint. All endpoints work when accessing from the docker container, except the health check.
We also don't get any error or anything, the application just breaks and the docker container stops automatically. I already debugged the application to see if any exception was thrown, but everything was fine. I also changed the code of the custom health check to retrieve a very simple: "Hello I'm healthy", which also didn't work.
Basically what we have is:
services.AddHealthChecks();
.
.
.
app.UseEndpoints(
endpoints =>
{
endpoints.MapHealthChecks("/health");
endpoints.MapControllers();
endpoints.MapGet("/", async (context) =>
{
context.Response.Redirect(context.Request.PathBase + "/swagger");
});
});
Unfortunatelly when I run the docker container, no output is shown. The container starts correctly though:
So here are two questions:
- Why only the
/healthendpoint does not work? - Why docker is not showing any log in the console when running the container?
This is my docker file:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source
COPY . .
RUN dotnet restore --configfile ./NuGet.Config
RUN dotnet publish "./MyProject/MyProject.csproj" -c Debug -o /app --no-restore
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app ./
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["dotnet", "MyProject.dll"]
EDIT:
My SQL Connection string was wrong. Now I created a appsettings.Docker.json which contains the correct connection string:
"Server=host.docker.internal\INSTANCE_NAME;Database=DATABASE_NAME;Trusted_Connection=True;MultipleActiveResultSets=true"
Still I cannot see any output from the dotnet cli in the docker.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

