Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafaeldalsenter/cf50b6847fbe289933642b65d5ea35a5 to your computer and use it in GitHub Desktop.
Save rafaeldalsenter/cf50b6847fbe289933642b65d5ea35a5 to your computer and use it in GitHub Desktop.

Revisions

  1. rafaeldalsenter created this gist Aug 10, 2022.
    22 changes: 22 additions & 0 deletions Dockerfile_trimming_singlefile.dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS publish
    WORKDIR /
    COPY ["WebApi/WebApi.csproj", "WebApi/"]

    RUN dotnet restore "WebApi/WebApi.csproj" --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"]