Below is a sample Docker Multistage build file I am working for a documentation.
'''
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS Dev
COPY *.csproj ./
WORKDIR /crud/
COPY . .
RUN dotnet publish -c Release -o output
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS runtime
ENTRYPOINT ["dotnet", "Asp.netCoreMvcCrud.dll"]
COPY --from=Dev /crud/output .
'''
So this copies, builds on stage one and
Copies the published binaries from stage one in final to create a skimmed image.
We should be able to manually build the image in a dev environment and copy the published binaries in a basic image and achieve the same skimmed size right?
like this
'''
FROM mcr.microsoft.com/dotnet/sdk:7.0
WORKDIR /crud
COPY publishedfolder ./
ENTRYPOINT ["dotnet", "Asp.netCoreMvcCrud.dll"]
'''
What else Multistage build gives as a advantage beyond Basic Image build and Builder Pattern?