Back to results for “Applications”
.NET › Docker & Containerization

What is Native AOT's benefit for containerized .NET applications specifically, beyond the general startup time improvement?

Advanced

Answer

For containers, Native AOT produces a fully self-contained native executable with no separate .NET runtime dependency, letting you use an extremely minimal base image (even distroless or scratch-based images with no OS package manager or shell at all), dramatically reducing both image size and attack surface compared to even a trimmed framework-dependent image -- combined with near-instant startup, this is particularly valuable for serverless/FaaS scenarios and horizontally auto-scaled services where fast cold starts directly reduce cost and improve responsiveness.
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -r linux-x64 -p:PublishAot=true -o /app

FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-jammy-chiseled AS final
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["/app/MyApp"]
Real-world example A serverless order-processing function switches to Native AOT with a chiseled Ubuntu base image, reducing both cold-start latency (from ~800ms to under 50ms) and image size (from 200MB to under 30MB), directly cutting both cost and user-perceived latency.

Common follow-ups: What is a 'chiseled' Ubuntu container image and how does it improve security?;What functionality is lost by adopting Native AOT (reflection-heavy libraries, etc.)?