Why ship the SDK and build tools to production? You only need the compiled binaries.
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY . . RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app COPY --from=build /app/out . ENTRYPOINT ["dotnet", "MyApp.dll"]
The Result: Faster deployments, smaller attack surface, and lower storage costs.
