There are a lot of articles and samples that illustrates how to build .net app in docker. This one is example. And all of them (that I found) contains similar steps:
- Copy proj file to image
- restore dependencies
- copy rest of src files to image
- Build...
In mentioned example this is:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY ["OktaMvcLogin.csproj", "./"]
RUN dotnet restore "./OktaMvcLogin.csproj"
COPY . .
RUN dotnet build "OktaMvcLogin.csproj" -c Release -o /ap
I'm wondering why to execute copy two times ? Why I can't just copy everything and then run restore and build?
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 as build
WORKDIR /src
COPY . .
RUN dotnet restore "myapp.csproj"
RUN dotnet build "myapp.csproj" -c Release -o /app
Is there any hidden sense in 2 times copy?