Last active
August 10, 2022 12:47
-
-
Save rafaeldalsenter/a000bb9a983fcfd8d2dbf44aa3d9a69a to your computer and use it in GitHub Desktop.
Dockerfile using trimming for .NET web applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS publish | |
WORKDIR / | |
COPY */*.csproj . | |
RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done | |
COPY *.sln . | |
RUN dotnet restore --runtime alpine-x64 | |
COPY . . | |
RUN dotnet publish "WebApi/WebApi.csproj" -c Release -o /app/publish \ | |
--no-restore \ | |
--runtime alpine-x64 \ | |
--self-contained true \ | |
/p:PublishTrimmed=true \ | |
/p: PublishSingleFile=true | |
FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine AS final | |
WORKDIR /app | |
EXPOSE 80 | |
EXPOSE 443 | |
COPY --from=publish /app/publish . | |
COPY /WebApi/appsettings.json . | |
ENTRYPOINT ["./WebApi"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment