Member-only story
Optimizing Docker Images is More Than Just a One-and-Done Thing in .NET.
I still remember my first time working with Docker in .NET. It felt like magic — wrapping up an entire application in a neat little container and running it anywhere.

But that magic wore off quickly when our CI/CD pipeline started to slow down, our cloud bills crept up, and debugging issues inside containers became a nightmare. Optimizing Docker images isn’t just a one-time fix; it’s an ongoing process that requires careful attention to detail, especially when working with .NET applications.
The Initial Excitement — and the First Signs of Trouble
Like many engineers, I started with a basic Dockerfile
that looked something like this:
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore
RUN dotnet publish -c Release -o /appFROM base AS final
COPY --from=build /app .
ENTRYPOINT ["dotnet", "MyApp.dll"]
At first glance, everything seemed fine. The image worked as expected, and deployments were smooth. But soon, I noticed that our…