Search code examples
c#azuredockerasp.net-core.net-8.0

Why does my Docker deployment via Azure not work after upgrading to .NET 8?


I'm upgrading from .NET 6 to .NET 8 and locally everything works perfect, but when I deploy my docker image to Azure I get the following in the log stream:

2025-02-26T14:30:21.885Z INFO - Waiting for response to warmup request for container myproj-beta_0_d6a7df18. Elapsed time = 226.3559545 sec
2025-02-26T14:30:25.921Z ERROR - Container myproj-beta_0_d6a7df18 for site services-beta did not start within expected time limit. Elapsed time = 230.3914614 sec

And this in the build log (not even sure if this is the cause):

025-02-26T12:57:08.9026334Z Exiting Configure : ....
2025-02-26T12:57:09.0881779Z Hosting environment: Production
2025-02-26T12:57:09.0882762Z Content root path: /opt/Kudu
2025-02-26T12:57:09.0883769Z Now listening on: http://0.0.0.0:8181
2025-02-26T12:57:09.0883839Z Application started. Press Ctrl+C to shut down.
2025-02-26T12:57:12.8498594Z Exception Message : An item with the same key has already been added. Key: System.Net.Http.Headers.HeaderDescriptor
2025-02-26T12:57:12.8571548Z Exception StackTrace : at System.Collections.Generic.Dictionary`2.TryInsert(TKey , TValue , InsertionBehavior )
2025-02-26T12:57:12.8572158Z at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
2025-02-26T12:57:12.8572255Z at System.Net.Http.Headers.HttpHeaders.GetOrCreateHeaderInfo(HeaderDescriptor , Boolean )
2025-02-26T12:57:12.8572286Z at System.Net.Http.Headers.HttpHeaderValueCollection`1.Add(T )
2025-02-26T12:57:12.8572324Z at Kudu.Core.Deployment.BuildServer.BuildService..ctor() in /tmp/KuduLite/Kudu.Core/Deployment/BuildServer/BuildService.cs:line 34
2025-02-26T12:57:12.8572356Z at System.RuntimeMethodHandle.InvokeMethod(Object , Span`1& , Signature , Boolean , Boolean )
2025-02-26T12:57:12.8572387Z at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )

With .NET 6, my deployment process worked fine:

  • Git push to Azure DevOps
  • Azure Pipeline runs
  • Builds docker image
  • Azure Web app deploys the latest image

Solution

  • The reason the container didn't start is because in .NET 8, the container default port changed to 8080. I had to add PORT=8080 in Azure environment variables. After that, everything worked fine.

    What's new in containers for .NET 8? The default port also changed from port 80 to 8080. To support this change, a new environment variable ASPNETCORE_HTTP_PORTS is available to make it easier to change ports. The variable accepts a list of ports, which is simpler than the format required by ASPNETCORE_URLS. If you change the port back to port 80 using one of these variables, you can't run as non-root.

    Source: https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8/containers