HTTP_PORTS when running ASP.NET 8 container in AKS
Asked Answered
H

4

11

In the logs of a ASP.NET 8 container I find this entry

[22:38:50 WRN] Overriding HTTP_PORTS '8080' and HTTPS_PORTS ''. Binding to values defined by URLS instead 'http://+:80'. # {"EventId": {"Id": 15}, "SourceContext": "Microsoft.AspNetCore.Hosting.Diagnostics"}

I do not understand where that HTTP_PORTS settings comes from, as none of the configuration sources I can think of set it.

Headspring answered 17/6, 2023 at 23:31 Comment(2)
Which configuration sources have you looked into?Tympany
@RehanRajput Application code, appsettings.*.json, environment variables, asp.net defaults, cluster .yaml filesHeadspring
R
14

This setup comes from the original images ans it can be viewed when inspecting the image, as the sample below:

"Env": [
            "DOTNET_USE_POLLING_FILE_WATCHER=1",
            "ASPNETCORE_ENVIRONMENT=Development",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "APP_UID=1654",
            "ASPNETCORE_HTTP_PORTS=8080",
            "DOTNET_RUNNING_IN_CONTAINER=true",
            "DOTNET_VERSION=8.0.0-rc.2.23479.6",
            "ASPNET_VERSION=8.0.0-rc.2.23480.2",
            "ASPNETCORE_URLS=http://+:5099"
        ], 

To avoid this warning you can set the environment variable ASPNETCORE_HTTP_PORTS, and comment the "ENV ASPNETCORE_URLS" line in your Dockerfile file and re-create the image again.

#ENV ASPNETCORE_URLS=http://+:5099
ENV ASPNETCORE_HTTP_PORTS=5099

I hope it helps you.

Roof answered 29/10, 2023 at 18:20 Comment(1)
Thanks so much for getting me on the right track! See my answer for an answer updated for the 8.0.0 release versions of aspnet docker images.Piercing
P
6

In the release versions of ASP.NET 8 docker images, the ASPNETCORE_HTTP_PORTS env variable is preset to 8080 (which is actually unnecessary, as this is the new default port anyways). See the extract from docker inspect mcr.microsoft.com/dotnet/aspnet:8.0:

"Env": [
  ...
  "ASPNETCORE_HTTP_PORTS=8080",
  ...
],

If you now use IWebHostBuilder.UseUrls(...) in your code, the above warning is triggered because the port set in the Docker image env variable is about to be overridden.

To avoid this error, simply remove the superfluous env variable from your Docker image before launching the app:

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY ./out .
# Add the line below
ENV ASPNETCORE_HTTP_PORTS= 
ENTRYPOINT [ "dotnet", "YourApp.dll" ]
Piercing answered 26/12, 2023 at 11:40 Comment(0)
W
1

I had to set ASPNETCORE_URLS="http://+:8008" as it was coming from the RedHat dotnet docker image. This was overriding the values I set to ASPNETCORE_HTTP_PORTS.

Writeoff answered 21/6 at 6:37 Comment(0)
N
0

You can instruct HostBuilder to skip any settings coming from environment variables is by setting WebHostBuilderOptions.SuppressEnvironment to true:

var hostBuilder = new HostBuilder()
    .ConfigureWebHost(web => {
        web.UseUrls("http://127.0.0.1:5052");
    }, options => {
        options.SuppressEnvironmentConfiguration = true;
    });
Navarrette answered 25/1 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.