skip to Main Content

I’m trying to deploy a .Net Core application to Azure web service with custom Windows container. The application works well in the Azure web service without container. But I cannot start it in the container.
I made the container to successfully start the app, but still cannot expose it to the port 443. It internally listens on port 5000:

Tried:

  1. Without WEBSITES_PORT and PORT app settings.
    The app starts and I can see "Now listening on: http://localhost:5000" in the log. However when I open the URL in browser, I receive "The containers without a port exposed will run in background mode."

  2. PORT=5000 or WEBSITES_PORT=5000
    The container fails to start. Or maybe – app service doesn’t recognise that the app started, because I can see "Now listening on: http://localhost:5000" in the application log.
    That’s how the log in Deployment Center looks like:

21/01/2024 18:40:09.953 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Start container succeeded.
21/01/2024 18:40:18.848 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Container has started.
21/01/2024 18:40:18.875 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Customizing the container
21/01/2024 18:40:20.938 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Container customization has completed successfully
21/01/2024 18:40:20.946 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Container has started.
21/01/2024 18:40:20.946 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Enabling Remote Management...
21/01/2024 18:40:21.111 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Remote Management has been enabled successfully!
21/01/2024 18:40:21.689 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Container entrypoint has started
21/01/2024 18:40:42.733 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Waiting for container to be ready. Container Id: 814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312
21/01/2024 18:41:03.795 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Waiting for container to be ready. Container Id: 814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312

... [this repeats multiple times]

21/01/2024 18:55:05.470 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Waiting for container to be ready. Container Id: 814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312
21/01/2024 18:55:26.514 WARNING - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Container is not ready in time
21/01/2024 18:55:26.515 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Container start-up and configuration completed successfully
21/01/2024 18:56:47.554 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000. It has failed 1 check(s). Container will be declared unreachable if it exceeds 3 consecutive failed checks.
21/01/2024 18:58:08.601 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000. It has failed 2 check(s). Container will be declared unreachable if it exceeds 3 consecutive failed checks.
21/01/2024 18:59:29.655 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000. It has failed 3 check(s). Container will be declared unreachable if it exceeds 3 consecutive failed checks.
21/01/2024 18:59:29.655 ERROR - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000
21/01/2024 18:59:29.655 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - CONTAINER_AVAILABILITY_CHECK_MODE app setting is set to ReportOnly.Container will not be recycled.For container to be reycled when it becomes unreachable set it to Repair
21/01/2024 19:00:50.704 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000. It has failed 1 check(s). Container will be declared unreachable if it exceeds 3 consecutive failed checks.
21/01/2024 19:02:11.744 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000. It has failed 2 check(s). Container will be declared unreachable if it exceeds 3 consecutive failed checks.
21/01/2024 19:03:32.765 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000. It has failed 3 check(s). Container will be declared unreachable if it exceeds 3 consecutive failed checks.
21/01/2024 19:03:32.765 ERROR - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - Failed to reach container's http endpoint. Check if application is healthy and exposed to Port: 5000
21/01/2024 19:03:32.765 INFO - Site: [app-service-name] - [814589c27f3f405bfd3cb9ac6c51b1110d95265f8bdeb069ce611f361b6b5312] - CONTAINER_AVAILABILITY_CHECK_MODE app setting is set to ReportOnly.Container will not be recycled.For container to be reycled when it becomes unreachable set it to Repair

2

Answers


  1. To resolve this issue, let’s break down the error log and solve the problem by following the step-by-step procedures.

    To understand the problem, I assumed that your .NET Core application is running inside a Windows container on Azure App Service, but it’s failing to expose the required port (5000) for the application to be accessible. Also, the application log indicates that the container starts, but it doesn’t become reachable on the specified port.

    Now, to solve this issue. The solution will start from the following:

    1. Your Dockerfile Configuration: Make sure your Dockerfile contains a line like this:

      EXPOSE 5000

    This will make Dockerfile exposes the correct port. The EXPOSE command in the Dockerfile tells Docker which ports to expose.

    1. Your Application Port Configuration: Check if your .NET Core application is configured to listen on the correct port internally. If No, then. In your application code (e.g., Program.cs or the configuration file), make sure the server is configured to listen on the expected port. It should resemble:

      public static IHostBuilder CreateHostBuilder(string[] args) =>
      Host.CreateDefaultBuilder(args)
      .ConfigureWebHostDefaults(webBuilder =>
      {
      webBuilder.UseStartup()
      .UseUrls("http://*:5000");
      });

    2. In your Azure App Service Configuration, check the WEBSITES_PORT and PORT application settings in the Azure Portal. Kindly, ensure these settings are not conflicting with the port your application is listening on. You might need to clear these settings if not needed.

    3. There might be a need for Docker container to explicit configured for Azure App Service to recognize the port sometimes. Therefore, you can add the following line in your Dockerfile to set the WEBSITES_PORT environment variable:

      ENV WEBSITES_PORT 5000

    4. Now, you have to perform heath check by implementing a health check endpoint in your .NET Core application if not already present, the code sould be similar to the following:

      public void ConfigureServices(IServiceCollection services)
      {
      services.AddHealthChecks();
      }

    if all the above is cool, and the problem persist. Let’s try more of checking.

    1. Check your Network security and Firewalls: Your network security groups or firewalls might be blocking traffic to or from your container. Ensure the necessary ports mentioned are open, and there are no restrictions on the network level.

    2. For the PORT 443, use HTTPS endpoint for your .NET Core application. By enable HTTPS in your application and ensure the necessary certificates are present in the container. The following is an example of a similar code you can modify as it is shown in option number 2 above:

      public static IHostBuilder CreateHostBuilder(string[] args) =>
      Host.CreateDefaultBuilder(args)
      .ConfigureWebHostDefaults(webBuilder =>
      {
      webBuilder.UseStartup()
      .UseUrls("http://:5000", "https://:443");
      });

    3. Application startup can be an issue sometimes. However, review the application’s startup process and handle any dependencies or configurations that might be missing. It’s just to ensure all dependencies are present in the container, and there are no startup issues.

    4. If you have done all the above correctly everything should be fine, you can enable diagnostics and check the detailed logs for any specific errors or warnings in case there more error and you can forward that for more analysis.

    5. Last but not the least, if all mentioned fails; consider rebuilding your container image and redeploying it to Azure App Service. Try to execute your Docker build and deployment steps again to ensure a fresh deployment.

    By following all these steps, you should be able to resolve the issues and have your .NET Core application running successfully within the Windows container on Azure App Service. Do not hesitate to let me know if you have any other questions.

    Login or Signup to reply.
  2. Add the following to your dockerfile or define PORT=5000 in the portal settings:
    EXPOSE 5000

    Make sure your app listens in that port and rebuild the container.

    If problem persist, please open a support ticket and we will assist:

    https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search