skip to content

With the .NET 10 SDK, how does dotnet publish /t:PublishContainer build an ASP.NET Core image without a Dockerfile, and what defaults does it apply?

level: middleimportance: must knowfreq 45%

answer

  1. EnableSdkContainerSupport on for non-library projects
  2. ContainerRepository defaults to AssemblyName
  3. tag latest, working directory /app/
  4. user from APP_UID, port from ASPNETCORE_HTTP_PORTS
  5. ContainerImageFormat: Docker or OCI

basics

~20 s

PublishContainer publishes the app and layers the output onto an inferred Microsoft base image (aspnet:10.0 for a web app), with no Dockerfile. It names the image after the assembly, tags it latest, and takes user and port from the base image.

solid answer

~40 s

`dotnet publish /t:PublishContainer` runs a normal publish and then builds an image itself: it pulls the base image's manifest and layers, adds the publish output as a new layer, writes the image config, and loads the result into the local Docker or Podman daemon, or pushes it when `ContainerRegistry` is set. `EnableSdkContainerSupport` defaults to `true` for any project whose output is not a library. Defaults: base `mcr.microsoft.com/dotnet/aspnet:10.0` for a framework-dependent web app (Ubuntu 24.04 in .NET 10); `ContainerRepository` = `$(AssemblyName)`, lowercased; tag `latest`; working directory `/app/`; entry point `dotnet /app/<App>.dll`. The user comes from the base image's `APP_UID` (non-root `app`, 1654) and the exposed port from its `ASPNETCORE_HTTP_PORTS` (8080). Override with `ContainerBaseImage` or `ContainerFamily`, `ContainerImageTags` (semicolon list) and, new in .NET 10, `ContainerImageFormat` (`Docker` or `OCI`).

code

xml · 7 lines
xml
<PropertyGroup>
  <TargetFramework>net10.0</TargetFramework>
  <ContainerRepository>quiz/game-api</ContainerRepository>
  <ContainerImageTags>1.4.0;latest</ContainerImageTags>
  <ContainerFamily>noble-chiseled</ContainerFamily>
  <ContainerImageFormat>OCI</ContainerImageFormat>
</PropertyGroup>

go deeper

for a junior

Know that dotnet publish /t:PublishContainer builds an image without a Dockerfile and that it is tagged latest by default.

for a middle

Explain the inferred base image, the repository, tag and working directory defaults, and how APP_UID and ASPNETCORE_HTTP_PORTS set the user and port.

for a senior

Configure tags, family, format and destination for CI, and decide when a Dockerfile is still needed for extra OS packages.

for a principal

Standardise how services build and tag images across teams, including base image pinning and when SDK-built images are mandatory.

## What PublishContainer does Since .NET 7 the SDK can build container images itself. For the **quiz-game API**, one command produces a runnable image, with no Dockerfile and no `docker build`: ```bash dotnet publish /t:PublishContainer ``` The `PublishContainer` target: 1. runs an ordinary `dotnet publish`; 2. works out the base image and fetches its manifest and layers from the registry; 3. adds the publish folder as a new layer at the working directory; 4. writes the image configuration: entry point, user, exposed ports, environment variables and OCI labels; 5. sends the image to its destination: the local Docker or Podman daemon by default, a remote registry when `ContainerRegistry` is set, or a `tar.gz` when `ContainerArchiveOutputPath` is set. `EnableSdkContainerSupport` defaults to `true` for any project whose `OutputType` is not `Library`. In .NET 10 that includes plain console apps, which previously had to opt in; web and worker projects already had it. ## The defaults, property by property | Property | Default in the .NET 10 SDK | Typical override | |---|---|---| | `ContainerBaseImage` | `mcr.microsoft.com/dotnet/aspnet:10.0` for a framework-dependent web app | a pinned tag or digest | | `ContainerFamily` | none (the default tag is Ubuntu 24.04 "noble" in .NET 10) | `noble-chiseled`, `alpine` | | `ContainerRepository` | `$(AssemblyName)`, normalised to lower case | `quiz/game-api` | | `ContainerImageTag` / `ContainerImageTags` | `latest` | `1.4.0;latest` | | `ContainerWorkingDirectory` | `/app/` | rarely changed | | `ContainerUser` | from the base image's `APP_UID` (1654, the `app` user) | `root` only if unavoidable | | `ContainerPort` | from the base image's `ASPNETCORE_HTTP_PORTS` (8080) | add ports as items | | `ContainerImageFormat` | inferred from the base image | `OCI` or `Docker` (new in .NET 10) | The base image is inferred from the project: `runtime-deps` for self-contained apps (including Native AOT), `aspnet` for ASP.NET Core projects, `runtime` for everything else, with the tag taken from the target framework (`10.0`). Setting `ContainerFamily` appends to that tag, for example `10.0-noble-chiseled`; setting `ContainerBaseImage` replaces the inference entirely. ## Tags and repository in CI `ContainerImageTag` sets one tag; `ContainerImageTags` takes a **semicolon-separated** list and produces one tagged image per entry. On a command line the semicolons need escaping for the shell, which is why many pipelines keep the list in the project file or pass a single tag: ```bash dotnet publish /t:PublishContainer -p:ContainerRepository=quiz/game-api -p:ContainerImageTag=1.4.0 ``` If the repository name contains characters a registry rejects, such as upper-case letters from `QuizGame.Api`, the SDK lower-cases it and warns. ## Non-root and port 8080 for free The SDK reads two environment variables from the Microsoft base images: - **`APP_UID`** (1654) becomes the image's user, so an SDK-built .NET 8+ image runs as the non-root `app` user even on the regular `aspnet` image; - **`ASPNETCORE_HTTP_PORTS`** (8080) becomes the exposed port. This is a difference from a hand-written Dockerfile on the regular `aspnet:10.0` image, which runs as root unless the Dockerfile adds `USER $APP_UID`. ## Pushing from CI In a pipeline the image usually goes to a registry rather than a local daemon: - set `ContainerRegistry` (for example `registry.example.com`); the SDK pushes over the registry HTTP API using the credentials of an earlier `docker login`, so the build agent needs no Docker daemon; - or set `ContainerArchiveOutputPath` to write a `tar.gz` that a scanner can inspect before a separate step pushes it; - pass the build number as the tag so each pipeline run produces an image that can be traced back to its commit. ## When a Dockerfile is still the better tool - you need `RUN` steps, such as installing an OS package the base image lacks; - the image must contain files produced outside `dotnet publish`; - the organisation's build platform only accepts Dockerfiles. For a typical ASP.NET Core API, the SDK path gives reproducible, non-root images with less to maintain.

  • Where does the image go if neither ContainerRegistry nor ContainerArchiveOutputPath is set?
    Into the local container daemon: the SDK detects Docker or Podman (or uses `LocalRegistry` if you set it) and loads the image there, so `docker run` can use it immediately. With `ContainerRegistry` it pushes to that registry using your existing `docker login` credentials; with `ContainerArchiveOutputPath` it writes a `tar.gz` for scanning or later loading.
  • What is the difference between ContainerFamily and ContainerBaseImage?
    `ContainerFamily` keeps the SDK's inference (repository and version tag) and only appends a variant such as `noble-chiseled` or `alpine` to the tag. `ContainerBaseImage` replaces the inference with the full image reference you give, including tag, and `ContainerFamily` is then ignored.

  • PublishContainer still needs a Dockerfile in the project folder.
  • The default image tag is the project's Version property.
  • SDK-built images on the regular aspnet base run as root unless you set ContainerUser.
  • ContainerImageTags takes a comma-separated list of tags.
  • The .NET 10 default aspnet:10.0 tag is a Debian image.

Assumes the .NET 10 SDK (10.0.4xx): default tags are Ubuntu-based, console apps get EnableSdkContainerSupport by default, and ContainerImageFormat is new in .NET 10.