Dockerfile for .Net Core 2.2

By James Kenny
1 min read

Table of Contents

I've written before about .net core with docker and using it with .net core 2.1

But as .net core has moved forward through new versions the docker files change, this is a sample docker file for a .net core 2.2 web app.

FROM microsoft/dotnet:2.2-sdk-alpine3.8 AS build

# copy csproj and restore as distinct layers
COPY *.sln .
COPY Serversncodenetcore2.2_docker/*.*.csproj ./Serversncodenetcore2.2_docker/
RUN dotnet restore

# copy everything else and build app
COPY Serversncodenetcore2.2_docker/. ./Serversncodenetcore2.2_docker/
WORKDIR /app/Serversncodenetcore2.2_docker
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.2.0-aspnetcore-runtime  AS runtime
COPY --from=build /app/Serversncodenetcore2.2_docker/out ./
ENTRYPOINT ["dotnet", "Serversncodenetcore2.2_docker.dll"]

The big difference from 2.1 is the images we use. In this case I am using the 2.2-sdk-alpine3.8 as my build image.


For the runtime I use the 2.2.0-aspnetcore-runtime


Last Update: September 09, 2019

About the Author