NET Core 5 应用程序。我添加了 docker-file 和运行正常的容器。我在我的应用程序中添加了健康检查。在我的应用程序中,我刚刚添加了 swagger 并添加了 sql 健康检查。下面是我的dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /source
EXPOSE 80
EXPOSE 443
# copy csproj and restore as distinct layers
COPY *.sln .
COPY ConfigService/*.csproj ./ConfigService/
RUN dotnet restore
# copy everything else and build app
COPY ConfigService/. ./ConfigService/
WORKDIR /source/ConfigService
RUN dotnet publish -c release -o /app --no-restore
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "ConfigService.dll"]
当我运行这个应用程序时它工作正常,当我打开 https://localhost:32788/swagger/index.html 它工作正常当我打开 https://localhost:32788/hc 这也工作正常但是当我打开https://localhost:32788/hc-ui 它告诉我它显示无法分配请求的地址 (localhost:32788) 下面是我在 appsettings.json 中的配置
"HealthChecksUI": {
"HealthChecks": [
{
"Name": "Health Check Service",
"Uri": "https://localhost:32788/hc"
}
],
"Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
],
"EvaluationTimeInSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60
}
下面是配置方法中的配置
app.UseHealthChecks(path: "/hc", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.UseHealthChecksUI(delegate (Options options)
{
options.UIPath = "/hc-ui";
});
我不确定为什么 https://localhost:32788/hc-ui 返回无法分配请求的地址 (localhost:32788)。由于我在 docker 内部运行,因此 Docker 将无法访问它正在运行的端口本身。有人可以帮我理解吗?任何帮助,将不胜感激。谢谢