'Docker compose specified port not mapping to connect to the health check endpoint

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

enter image description here



Solution 1:[1]

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

version: '3.4'

services:
  testapp.api:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "8005:80"
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

  webstatus:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - HealthChecksUI__HealthChecks__0__Name=Test App API Health Check
      - HealthChecksUI__HealthChecks__0__Uri=http://testapp.api/hc
    ports:
      - "8006:80"
    depends_on:
      - testapp.api
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PicBuilder