I have a Dockerfile with a multistage build (most the file was generated by VS). When I build my application via Docker on my Windows 10 machine everything works fine.
When I try to build on a Windows 2019 Standard server I get this error:
Step 13/20 : WORKDIR "/src/Dining.Api"
---> Using cache
---> 63b85c1e029d
Step 14/20 : RUN dotnet build "Dining.Api.csproj" -c Release -o /app
---> Running in 02a2e5f36cac
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): error : Access to the path 'C:\src\Dining.Domain\obj\Dining.Domain.csproj.nuget.dgspec.json' is denied. [C:\src\Dining.Api\Dining.Api.csproj]
Build FAILED.
C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): error : Access to the path 'C:\src\Dining.Domain\obj\Dining.Domain.csproj.nuget.dgspec.json' is denied. [C:\src\Dining.Api\Dining.Api.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:05.06
The command 'cmd /S /C dotnet build "Dining.Api.csproj" -c Release -o /app' returned a non-zero code: 1
When I build on my Windows 10 machine here is the output from the same step in the docker build:
Step 13/20 : WORKDIR "/src/Dining.Api"
---> Running in e7be7be7e992
Removing intermediate container e7be7be7e992
---> 265b7c6ade96
Step 14/20 : RUN dotnet build "Dining.Api.csproj" -c Release -o /app
---> Running in 9c0d92e0df82
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 440.05 ms for /src/Dining.DataAccess/Dining.DataAccess.csproj.
Restore completed in 43.97 ms for /src/Dining.Domain/Dining.Domain.csproj.
Restore completed in 62.16 ms for /src/Dining.Service/Dining.Service.csproj.
Restore completed in 1.1 sec for /src/Dining.Api/Dining.Api.csproj.
Dining.Domain -> /app/Dining.Domain.dll
Dining.DataAccess -> /app/Dining.DataAccess.dll
Dining.Service -> /app/Dining.Service.dll
Dining.Api -> /app/Dining.Api.dll
Build succeeded.
0 Warning(s)
0 Error(s)
I'm running docker version 19.03.1 on both my machine and the Windows Server. Here is the docker file:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["Dining.Api/Dining.Api.csproj", "Dining.Api/"]
COPY ["Dining.Domain/Dining.Domain.csproj", "Dining.Domain/"]
COPY ["Dining.DataAccess/Dining.DataAccess.csproj", "Dining.DataAccess/"]
COPY ["Dining.Service/Dining.Service.csproj", "Dining.Service/"]
COPY ["NuGet.Config", "./"]
RUN dotnet restore "Dining.Api/Dining.Api.csproj"
COPY . .
WORKDIR "/src/Dining.Api"
RUN dotnet build "Dining.Api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Dining.Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Dining.Api.dll", "--server.urls", "http://*:80"]
I researched and found this: https://github.com/NuGet/Home/issues/7836 It gives a lot of detail about the error but doesn't really provide a solution. I tried using a .dockerignore to exclude copying files in the **/obj/ directory but the problem continued. Has anyone experienced this issue and come up with a solution/work-around?
I managed to solve a similar issue by adding
USER Administrator
To the docker file as seen in : DotNet 6 fails to run in a Windows container: Permission denied
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With