Why does an ASP.NET Core 10 app in an official .NET container listen on port 8080 instead of 80, and which user does it run as?
answer
- ASPNETCORE_HTTP_PORTS=8080 in the image
- ports below 1024 need privileges
- user app, APP_UID=1654
- chiseled images set USER $APP_UID
- docker run -p 8000:8080
basics
~20 sSince .NET 8 the official images set ASPNETCORE_HTTP_PORTS=8080 so the app can run as the non-root app user (APP_UID 1654), which cannot bind port 80. SDK-built and chiseled images run as that user; a Dockerfile on the regular image needs USER $APP_UID.
solid answer
~50 sSince .NET 8 the official images set `ASPNETCORE_HTTP_PORTS=8080` instead of binding port 80, and they define a non-root user **`app`** whose id is in **`APP_UID` (1654)**. Ports below 1024 are privileged on Linux, so a process running as `app` could not bind 80 by default; 8080 makes rootless the easy path. So you map the host port to 8080: `docker run -p 8000:8080 ...`, and probes and ingress rules target 8080. Which user actually runs the app depends on how the image was built: **SDK-built images** (`/t:PublishContainer`) read `APP_UID` and run as 1654; **chiseled images** set `USER $APP_UID` themselves; a **Dockerfile on the regular `aspnet:10.0` image** still runs as **root** unless it adds `USER $APP_UID`. Running as `app` also means the app cannot write to `/app`; write to a volume or a directory owned by that user.
code
dockerfile · 6 linesFROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY ./publish .
# the regular image defines the app user but does not switch to it
USER $APP_UID
ENTRYPOINT ["dotnet", "QuizGame.Api.dll"]go deeper
Remember that .NET 8+ containers listen on 8080, so port mappings and probes must target 8080.
Explain ASPNETCORE_HTTP_PORTS, the app user and APP_UID, and why rootless and port 8080 go together.
Know which builds actually run as non-root, and fix the file-permission, volume and Data Protection fallout of running as uid 1654.
Set the organisation's container baseline: non-root everywhere, TLS at the edge, and exceptions to root reviewed and recorded.
## The .NET 8 change that still trips people up Before .NET 8, the official ASP.NET Core images set `ASPNETCORE_URLS` to listen on port 80, and containers ran as root. .NET 8 changed both defaults, and .NET 10 images keep them: - the images set **`ASPNETCORE_HTTP_PORTS=8080`**, a simpler alternative to `ASPNETCORE_URLS` that takes a semicolon-separated list of ports; - the images define a non-root user and group named **`app`**, with the id stored in **`APP_UID=1654`**. The two go together. Ports below 1024 are privileged on Linux, so a process that is not root cannot bind port 80 by default. Moving the default to 8080 lets the app run as `app` without extra capabilities. ## What you have to change | Before .NET 8 | .NET 8 and later | |---|---| | `docker run -p 8000:80 quiz-api` | `docker run -p 8000:8080 quiz-api` | | Health probe on port 80 | Health probe on port 8080 | | Service or ingress `targetPort: 80` | `targetPort: 8080` | If you map host port 8000 to container port 80 on a .NET 8+ image, the connection is reset: nothing listens on 80. One more catch: apps still built on the obsolete `WebHost.CreateDefaultBuilder` ignore `ASPNETCORE_HTTP_PORTS` and fall back to `http://localhost:5000`, which is unreachable from outside the container. ## Who the process runs as The images define the `app` user, but whether the container **uses** it depends on the image and how you built it: | Image and build | Runs as | |---|---| | SDK-built (`dotnet publish /t:PublishContainer`) on any Microsoft .NET 8+ base | `1654` (`app`): the SDK reads `APP_UID` from the base image and sets the user | | Dockerfile on a chiseled image (`aspnet:10.0-noble-chiseled`) | `1654`: the chiseled image itself declares `USER $APP_UID` | | Dockerfile on the regular image (`aspnet:10.0`) | **root**, unless the Dockerfile adds `USER $APP_UID` | The regular images only **offer** the user, as an opt-in; this is the detail interviewers probe. For the quiz-game API built with the SDK, nothing extra is needed: the image already runs as 1654 and exposes 8080. To run an SDK-built image as root (for example, a legacy tool that needs it), set `<ContainerUser>root</ContainerUser>`; treat that as an exception to justify, not a default. ## What non-root changes for the app Running as `app` is safer, and it surfaces assumptions the app made as root: - **The app directory is not writable.** Files under `/app` belong to root, so code that writes logs, uploads or caches next to the binaries fails with an access-denied error. Write to a mounted volume or to a directory the `app` user owns, such as its home directory. - **Data Protection keys** written to the default location must go to a persisted, writable path in production, or every restart invalidates cookies and antiforgery tokens. - **Volumes** mounted from the host must be readable and writable by uid 1654, not just by root. - **Binding to 80 or 443 inside the container** fails unless you grant the capability; keep 8080 inside and let the ingress or load balancer expose 80 and 443. ## Checking what an image will do You do not have to guess. `docker inspect` on the built image shows its `User` and `ExposedPorts` settings: an SDK-built image of the quiz-game API reports user `1654` and port `8080/tcp`, because the SDK copies them from `APP_UID` and `ASPNETCORE_HTTP_PORTS`. A Dockerfile-built image on the regular base shows an empty user, which means root. Checking this in CI catches a Dockerfile that lost its `USER` line during a refactor. ## In the quiz-game API's pipeline 1. Build the image with `dotnet publish /t:PublishContainer`; it runs as 1654 on 8080. 2. Point the orchestrator's container port, readiness and liveness probes at 8080. 3. Mount any writable storage with ownership for uid 1654. 4. Terminate TLS at the ingress, so the container never needs port 443.
- Does every .NET 10 container run as non-root by default?No. SDK-built images do, because the SDK sets the user from the base image's `APP_UID`, and chiseled images do, because they declare `USER $APP_UID`. A Dockerfile based on the regular `aspnet:10.0` image runs as root until it adds `USER $APP_UID`. The `app` user exists in all of them; only some switch to it.
- The app starts but every upload fails with access denied after moving to the non-root user. Why?The process now runs as uid 1654, and the publish output under `/app` is owned by root, so writing next to the binaries is refused. Write uploads to a mounted volume or another directory owned by the `app` user, and make sure host-mounted volumes grant uid 1654 write access.
- A .NET 10 ASP.NET Core container listens on port 80 by default.
- Every container built from an official .NET 8+ image automatically runs as non-root.
- APP_UID is a port number that ASP.NET Core reads to choose its listening port.
- Running as the app user lets the process write anywhere under /app.
- Mapping -p 8000:80 works because Docker redirects to 8080 automatically.
Assumes .NET 10 images; port 8080 via ASPNETCORE_HTTP_PORTS and the app user (APP_UID 1654) are the defaults since .NET 8, while earlier images listened on port 80.