.NET › Docker & Containerization
What are the official .NET Docker base images, and what's the difference between the sdk, aspnet, and runtime image variants?
BeginnerAnswer
The sdk image (mcr.microsoft.com/dotnet/sdk) includes the full SDK for building and publishing applications -- large, used only in build stages. The aspnet image (mcr.microsoft.com/dotnet/aspnet) includes the ASP.NET Core runtime for running web applications -- smaller, used as the final production base for web apps. The runtime image (mcr.microsoft.com/dotnet/runtime) includes just the base .NET runtime without ASP.NET Core-specific components, for non-web console/worker applications.
# Building a console app: runtime is sufficient (smaller than aspnet)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS final
# Building a web API: needs aspnet for Kestrel, MVC, etc.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS finalReal-world example A background worker service that processes messages and has no web endpoints uses the smaller dotnet/runtime base image instead of dotnet/aspnet, avoiding unnecessary ASP.NET Core components it will never use.