Created
April 5, 2018 15:35
-
-
Save frostyandy2k/9c6492a78b7d9952c1ab11e5ad4faf04 to your computer and use it in GitHub Desktop.
Dotnet Core Docker multi stage build and runtime for webapi projects
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 microsoft/dotnet:2.1-sdk AS build-env | |
WORKDIR /app | |
# copy csproj and restore as distinct layers | |
COPY *.csproj ./ | |
RUN dotnet restore | |
# copy everything else and build | |
COPY . ./ | |
# RUN dotnet build -c Release | |
RUN dotnet publish -c Release -o out | |
################## | |
# Production image | |
FROM microsoft/dotnet:2.1-runtime-alpine AS deploy-env | |
# use aspnet core https://github.com/NileshGule/dotnet-2017/blob/master/DotNet2017/CoreWebAPI/Dockerfile | |
# Upgrade to newest packages | |
RUN apk update && apk upgrade | |
# RUN apk add libc6-compat libunwind | |
#Timezone | |
RUN apk add tzdata && cp /usr/share/zoneinfo/UTC /etc/localtime | |
RUN echo "UTC" > /etc/timezone | |
RUN date && apk del tzdata | |
# Default port for this App Skeleton, will be exposed when -P specified | |
ENV ASPNETCORE_URLS=http://+:5050 | |
# EXPOSE 80 | |
EXPOSE 5050 | |
# Copy from build stage | |
WORKDIR /app | |
COPY --from=build-env /app/out ./ | |
# using array notation causes node to be PID1 and will not exit properly. Without the array notation the shell forwards the sigterm correctly. | |
ENTRYPOINT ["dotnet", "dotnet-api-backend-skeleton.dll"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment