我有一个多阶段构建的 Dockerfile(大多数文件是由 VS 生成的)。当我通过 Docker 在我的 Windows 10 机器上构建我的应用程序时,一切正常。
当我尝试在Windows 2019 标准服务器上构建时,我收到此错误:
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
当我在我的Windows 10机器上构建时,这里是 docker 构建中同一步骤的输出:
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)
我在我的机器和 Windows Server 上运行 docker 版本 19.03.1。这是泊坞窗文件:
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"]
我研究并发现了这一点:https ://github.com/NuGet/Home/issues/7836 它提供了很多关于错误的详细信息,但并没有真正提供解决方案。我尝试使用 .dockerignore 排除复制 **/obj/ 目录中的文件,但问题仍然存在。有没有人遇到过这个问题并提出解决方案/解决方法?