Docker File for .NET Core 3.1

By James Kenny
1 min read

Table of Contents

This is my sample docker file I use for .net core 3.1 projects.

FROM AS build


# copy csproj and restore as distinct layers
COPY *.sln .
COPY X.Web/*.*.csproj ./X.Web/
COPY X.Models/*.*.csproj ./X.Models/
COPY X.Data/*.*.csproj ./X.Data/
RUN dotnet restore

# copy everything else and build app
COPY X.Web/. ./X.Web/
COPY X.Models/. ./X.Models/
COPY X.Data/. ./X.Data/

WORKDIR /app/X.Web

RUN dotnet publish -c Release -o out

FROM AS runtime
COPY --from=build /app/X.Web/out ./
ENTRYPOINT ["dotnet", "X.Web.dll"]

This sample has 3 projects in the solution to show how it all ties together.

I mentioned in my other post on  Things I've found while Upgrading to .NET Core 3.1 why  I switched to Bionic for my base images.

Last Update: January 20, 2020

About the Author