Last active
December 22, 2019 14:57
-
-
Save eSlider/e0172d102b9a12231f01849dfacb0e76 to your computer and use it in GitHub Desktop.
Dramatically shrinking .net core 3.1 docker image publishing size
This file contains hidden or 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
# Officia microsoft .NET SDK image | |
FROM mcr.microsoft.com/dotnet/core/sdk:latest AS api-build | |
# Set directory for build | |
WORKDIR /app | |
# Copy anything from where docker would be builded | |
COPY ./. ./ | |
# Reice packages, Build and shrink as an standalone exutable file | |
RUN dotnet publish -c Release -r linux-musl-x64 /p:PublishSingleFile=true /p:PulishTrimmed=true -o out | |
# Very small linux as an base for service | |
FROM alpine:latest AS runtime | |
# Set directory to run from | |
WORKDIR /app/ | |
# Copy .NET exutable to small linux image | |
COPY --from=api-build /app/out/. . | |
# Install libraries to .NET exutable work | |
RUN apk update && apk add --no-cache libstdc++ libgcc gcompat musl libc6-compat libintl icu-dev icu | |
# Allow to redirect and get work .NET web service from any host | |
# But needs to open(dispose) ports by run docker | |
ENV ASPNETCORE_URLS=http://+:80 | |
# Doesn't work but defined :) | |
# Right way example: docker run -t service -p80:80 . | |
EXPOSE 80 | |
# Run service as standalone exutable by default | |
# But you can easily override antry point | |
# Example: docker build -t project-service . && docker run project-service | |
ENTRYPOINT ["/app/ProjectService"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment