Dockerize .NET: SDK Builds, Runtime-Only Images, Production Ready
Microsoft publishes excellent .NET Docker images, but most teams use them incorrectly - shipping the SDK image to production or missing the chiseled variants that cut image size in half. We build .NET containers using the proper SDK/runtime split with chiseled base images, non-root users, and health check endpoints.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
Why Dockerize .NET
The .NET SDK image is 800+ MB - it includes compilers, NuGet tooling, and debug symbols you never need in production. Yet many teams deploy with FROM mcr.microsoft.com/dotnet/sdk:8.0 because the Dockerfile was copy-pasted from a tutorial.
A proper multi-stage build uses the SDK image for dotnet publish and a runtime-only or chiseled image for the final stage, cutting image size to 80-120 MB and removing the attack surface of build tooling.
Our Docker Implementation for .NET
Two-stage build using Microsoft's official images:
- Build stage:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build- runsdotnet restorefirst (lockfile layer cache), thendotnet publish -c Release -o /app/publish --no-restorewith optional-p:PublishTrimmed=truefor AOT-compatible apps. - Runtime stage:
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled- the chiseled variant is a distroless-like Ubuntu image with no shell, no package manager, and non-root by default. Copies published output to/app.
Compose file sets ASPNETCORE_URLS=http://+:8080, maps the port, includes a health check against /health, and sets DOTNET_EnableDiagnostics=0 to disable diagnostics in production.
What You Get
- Multi-stage
Dockerfilewith chiseled runtime image - 80-120 MB docker-compose.ymlwith health checks, resource limits, and non-root execution- NuGet restore layer caching for fast rebuilds
- Optional native AOT build for sub-50 MB images and millisecond startup
- CI pipeline with
dotnet restorecache and Docker layer cache
相关服务
Privacy & anti-censorship guides
Why Anubiz Host
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.