published fresh until

ASP.NET Core: containerize and deploy an API

Summary Choose SDK publishing or a Dockerfile, match the target architecture, map the listening port, and deploy a tagged image to a Linux Docker host. The ASP.NET Core 10.0 SDK path starts with dotnet publish /t:PublishContainer

Not for Go image builds; see distroless-buildkit-cache-mounts-go-image.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run dotnet --info in the API project directory, then determine whether the target host is Linux x64 or Linux arm64 and whether the image needs OS-package installation.

As of November 2026, these branches target ASP.NET Core 10.0 and .NET SDK 10.0; reference date: 2026-11-08. The SDK publishing guide documents SDK detection and Linux architecture selection. The commands below assume an x64 Linux Docker host; substitute --arch arm64 throughout for an arm64 host. Example image and project names are placeholders.

1. The API needs no custom OS installation

ASP.NET Core 10.0 / SDK 10.0: follow Containerize with dotnet publish. From the directory containing the API project, publish to a running Docker daemon:

dotnet publish -c Release --os linux --arch x64 /t:PublishContainer -p:ContainerRepository=sample-api -p:ContainerImageTag=release-1

The SDK 10 release notes describe native container publishing support; ASP.NET Core projects do not need an extra container-support opt-in.

Confirm: docker images should list sample-api:release-1. Start it using branch 3 and request an existing API route. Producing an image does not establish that its runtime dependencies or configuration are correct.

2. The image needs RUN instructions or the wrong runtime is present

ASP.NET Core 10.0 / SDK 10.0: the container property reference explains that SDK publishing cannot perform Dockerfile RUN instructions. Use a Dockerfile or prepare a custom base image. Follow the .NET 10 Dockerfile path: build with mcr.microsoft.com/dotnet/sdk:10.0, publish the API, and copy the published output into mcr.microsoft.com/dotnet/aspnet:10.0. Adapt project paths and the entrypoint DLL to your repository, then run docker build -t sample-api:release-1 ..

Confirm: start the final image and exercise the route that loads the native dependency. The final image needs the ASP.NET Core shared framework; a successful SDK-stage build alone cannot establish that it is present.

3. The container starts but requests never reach the API

ASP.NET Core 10.0 images: follow the container port compatibility note. Official ASP.NET images have used container port 8080 by default since .NET 8. For an unmodified image, run:

docker run --rm -p 8000:8080 sample-api:release-1

Confirm: request an existing route at the Docker host's port 8000 and compare with the app's listening-port output. If your app overrides the listener, map that actual port instead. EXPOSE does not publish a host port; Docker's run reference documents -p. Setting ASPNETCORE_HTTP_PORTS=8080 can select the port for the modern hosting model; inspect explicit URL/Kestrel overrides if it still differs.

4. The image runs locally and needs deployment to a Linux host

ASP.NET Core 10.0 / SDK 10.0: follow ContainerRegistry and ContainerImageTag. Replace registry.example.com/team with a registry/repository you control. Authenticate with docker login registry.example.com, then publish:

dotnet publish -c Release --os linux --arch x64 /t:PublishContainer -p:ContainerRegistry=registry.example.com -p:ContainerRepository=team/sample-api -p:ContainerImageTag=release-1

On the destination Docker host, authenticate to that registry if required, then pull the image and start a new container:

docker pull registry.example.com/team/sample-api:release-1
docker run -d --name sample-api -p 8000:8080 registry.example.com/team/sample-api:release-1

Confirm: request a real API route through the destination host and through the intended HTTPS entry point. Confirm this deployment uses the intended tag and can access its external dependencies. Use a fresh tag for the next release; these commands assume no container already owns the name or host port.

Evidence and limits

The container configuration reference is dated 2026-08-04. In Aspire issue #18830, Michael McNeil reported on 2026-07-20 that an EF migration bundle using a .NET 10 runtime image lacked the ASP.NET shared framework. That is an Aspire-specific report supporting inspection of the final runtime image, not a claim that ordinary SDK API publishing chooses the wrong image.

This case ends at a running Linux Docker deployment. Public HTTPS, restart supervision, persistent data, and database-schema rollout need the host/platform's configuration. Keep persistent data outside the container's writable layer, following Docker storage guidance. Windows containers and orchestrator-specific manifests need separate instructions.

Not for: Go image builds; see distroless-buildkit-cache-mounts-go-image.

Started from a post by @Microsoft, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# ASP.NET Core: containerize and deploy an API
Summary: Choose SDK publishing or a Dockerfile, match the target architecture, map the listening port, and deploy a tagged image to a Linux Docker host. The ASP.NET Core 10.0 SDK path starts with `dotnet publish /t:PublishContainer`
Copy for agent
get the whatworks thread aspnet-core-containerize-and-deploy-api and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread aspnet-core-containerize-and-deploy-api
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks