Docker组合指定的端口不映射以连接到健康检查端点
我是Docker的新手。这是我正在使用的布局。我在Docker组成的文件中有2个项目。 DotNet6 Web API和MVC Web应用程序。在Web API startup.cs中,我有以下代码,可以使用Aspnetcore.healthchecks.ui获得健康状态,如果我浏览到端点,我会得到健康检查值的JSON对象(此部分工作)
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
});
我有一个WebStatus .Net Core MVC应用程序的工作是使用HealthCheck UI显示健康统计数据。 对此的应用程序是:
{
"HealthChecks-UI": {
"HealthChecks": [
{
"Name": "TestApp API Health Check",
"Uri": "https://localhost:7100/hc"
},
{
"Name": "TestApp API Health Check (Local)",
"Uri": "https://localhost:7141/hc"
}
],
"Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
],
"EvaluationTimeOnSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
则Docker组成的文件如下所示
version: '3.4'
services:
testapp.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "8005:80"
- "7100:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
webstatus:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- HealthChecksUI__HealthChecks__0__Name=Test App API Health Check
- HealthChecksUI__HealthChecks__0__Uri=https://testapp.api/hc
ports:
- "8006:80"
- "7101:443"
depends_on:
- testapp.api
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
如果我在没有Docker的两个项目中启动两个项目,一切正常,WebStatus应用程序显示API的健康状况如下所预期, !但是,当我使用Docker组合运行此功能时,它行不通。我用来进入WebStatus应用程序的URL是https:// localhost:7101/healthchecks-ui#/healthchecks
I am a newbie to docker. This is the layout I am working with. I have 2 projects in the docker compose file. A dotnet6 web api and a mvc web app. In the web api startup.cs I have the following code to get health statuses using AspNetCore.HealthChecks.UI, If I browse to the endpoint I get a json object of health check values (this part works)
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
});
I have a WebStatus .Net core MVC app whose job is to display health stats using the healthcheck UI.
The appsetting for this is:
{
"HealthChecks-UI": {
"HealthChecks": [
{
"Name": "TestApp API Health Check",
"Uri": "https://localhost:7100/hc"
},
{
"Name": "TestApp API Health Check (Local)",
"Uri": "https://localhost:7141/hc"
}
],
"Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
],
"EvaluationTimeOnSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
And the docker compose file is as shown below
version: '3.4'
services:
testapp.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "8005:80"
- "7100:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
webstatus:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- HealthChecksUI__HealthChecks__0__Name=Test App API Health Check
- HealthChecksUI__HealthChecks__0__Uri=https://testapp.api/hc
ports:
- "8006:80"
- "7101:443"
depends_on:
- testapp.api
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
If I start both the projects without docker, everything works, the WebStatus app shows the health status of the api as expected! However it doesn't work when I use docker compose to run this. The url I use to get to the webstatus app is https://localhost:7101/healthchecks-ui#/healthchecks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,WebStatus应用程序无法通过HTTPS进行通信。我更改了所有内容以通过HTTP进行交流,然后开始工作
It turns out that the the webstatus app was not able to communicate over https. I changed everything to communicate over http and it started working