9

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?

jwdenny13
  • 629
  • 1
  • 11
  • 21
  • 1
    As a follow up, I was able to get around the issue. In my original post I mentioned I attempted creating a .dockerignore but I said that didn't work. I just realized I was putting the .dockerignore in the project folder, not in the root of the solution. When I added a .dockerignore to the solution root, then added a **/obj/ line, I was able to build the image on Windows Server 2019. – jwdenny13 Aug 29 '19 at 17:28
  • I think the issue is that you're using Linux containers locally, but Windows containers on the server. If you're going to deploy to Windows, use Windows containers in development as well. If you switch over, you'll have the same problem in reverse: your development build will fail. Then, just modify your Dockerfile to work for the Windows containers in development, and you'll be good to go on the server. – Chris Pratt Aug 29 '19 at 17:58
  • Thank you for the response Chris. On my dev machine I switched docker from Linux to Windows but I didn't get the error. I'm only seeing the error on the Windows 2019 Standard server. You mentioned modifying the Dockerfile to work for Windows containers - can you explain how to do that? I was under the impression the aspnetcore-runtime and sdk images worked on both Windows and Linux. – jwdenny13 Sep 03 '19 at 12:17
  • They do. The problem is your paths. – Chris Pratt Sep 03 '19 at 12:37

1 Answers1

4

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

cdup
  • 49
  • 4