-
I only see this in Linux Azure Container Instances (ACI) but I figured it's more appropriate to ask here instead of the Azure forums since the issue only appeared after upgrading the app to .NET 8; the exact same code works targeting .NET 6 (i.e. if I only change I get the following exception when launching a .NET 8 ASP.NET Core app in an ACI:
This happens if I try to make Kestrel listen on ports 80, 443, or both. I don't get any more information with This is what I tried:
I can't reproduce this locally under Windows. The container image is published self-contained. Can somebody help me understand what I may be doing wrong? Is this perhaps an undocumented breaking change, in .NET 8 or how ACI supports .NET 8? Update: cross-posted this to Stack Overflow since nobody replied here for a week. Update 2: I cross-posted to Microsoft Q&A for visibility. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 13 replies
-
You can explicitly configure Kestrel to bind to port 80 during the WebApplication build at startup:
In Container Apps, I found that all of ASPNETCORE_HTTP_PORTS, the ingress port, and the probe ports have to be aligned. If explicitly binding during build, environment variables port values are ignored. Given what I understand, I'm surprised setting port 80 in the environment did not work for you. Are you able to console to the container to confirm that value? |
Beta Was this translation helpful? Give feedback.
-
I dug some more and found that actually this might be the breaking change relevant to this issue, not the default port change: New non-root 'app' user in Linux images. Also see the blogpost it links. And sure enough, with .NET 6 the container's user is I tried
to run the container as root but it still runs as I cross-posted to Microsoft Q&A for visibility. |
Beta Was this translation helpful? Give feedback.
-
Found the solution. It was actually setting ContainerUser with So, all in all, compared to the .NET 6 version, my app has the following changes to target .NET 8:
Full section of the csproj: <PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>MyId</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
<ContainerUser>root</ContainerUser>
</PropertyGroup> I did try this before, but apparently I messed up something during publishing, but now it's clear. I also opened an issue to clarify this in the docs: dotnet/docs#39082. Thanks for your help @elruss! |
Beta Was this translation helpful? Give feedback.
-
Is this really the best solution? I thought it was bad practice to run containers as the root user? |
Beta Was this translation helpful? Give feedback.
-
This is not just an Azure Container issue; Bare Metal Linux (haven't tried many flavors besides Ubuntu) also disallows running non-root on 443/80. Not a big deal though, as mentioned above :44300 or :8080 e.g. both work fine. |
Beta Was this translation helpful? Give feedback.
-
@Piedone I was able to run .NET 8 Web API containerized application, all is related to breaking change to use non-root user as you suspected. https://devblogs.microsoft.com/dotnet/running-nonroot-kubernetes-with-dotnet/ In Dockerfile just expose the non-root port for HTTP and HTTPS: EXPOSE 8080 And target such ports from the Service in Kubernetes. |
Beta Was this translation helpful? Give feedback.
Found the solution. It was actually setting ContainerUser with
<ContainerUser>root</ContainerUser>
in the csproj. No other changes necessary.So, all in all, compared to the .NET 6 version, my app has the following changes to target .NET 8:
<TargetFramework>net8.0</TargetFramework>
in the csproj.<TargetFramework>net8.0</TargetFramework>
in the pubxml used byaz container create
.<ContainerUser>root</ContainerUser>
in the csproj, see below the context.Full section of the csproj: