For anyone who is also struggling with this question but dotnet restore
is taking a very long time, I created a Dockerfile below that solved this issue for me:
FROM mcr.microsoft.com/dotnet/sdk:5.0
WORKDIR /App
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY ./test ./
RUN dotnet publish -c Release -o out
# run tests on docker run
ENTRYPOINT ["dotnet", "test"]
Note: I didn't include RUN dotnet test
in my Dockerfile as this would stop the build if the tests failed and this did not suit my scenario
I also had a .dockerignore file with the following contents:
bin/
obj/
For reference, this was my folder structure:
/bin/
/obj/
/test/*.cs
/.dockerignore
/Dockerfile
/testing.csproj