[英]CS0016 using dotnet build/publish with --output parameter when running in Server Core Docker EE container
我有一個 Windows docker 容器在帶有 Docker EE 的服務器核心上運行。 當我嘗試運行dotnet build
或dotnet publish
時,我收到 CS0016 'Could not write to output file' 錯誤。
這是 Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
# copy csproj and restore as distinct layers
WORKDIR /src
COPY *.sln ./
COPY nuget.config ./
COPY API.Core/*.csproj ./API.Core/
COPY API.Core.Service/*.csproj ./API.Core.Service/
RUN dotnet restore
# copy everything else and build app
COPY . .
RUN dotnet publish API.Core/API.Core.csproj -c release -o /app --no-restore
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS final
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "API.Core.dll"]
在容器內交互運行,我可以看到所有的源文件都在 C:\src
dotnet publish API.Core/API.Core.csproj -c release --output /app
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
CSC : error CS0016: Could not write to output file 'C:\src\API.Core.Service\xmldocs.xml' -- 'Access to the path 'C:\
src\API.Core.Service\xmldocs.xml' is denied.' [C:\src\API.Core.Service\API.Core.Service.csproj]
我覺得奇怪的是“輸出文件”的路徑不是 C:\app\API.Core.Service\xmldocs.xml - 好像--output
參數被忽略了。
我嘗試過的事情:
構建 Dockerfile 並運行容器在我運行 Docker 桌面的筆記本電腦上運行良好。
錯誤消息是否具有誤導性,“輸出文件”真的是源文件嗎?
其中大部分內容是從https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-的 MS 文檔中復制和調整的5.0
在 Docker 配置中,您將目錄從WORKDIR /app
更改為WORKDIR /src
,同時將代碼發布到 /app。 更改 Docker 文件以使其工作:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
# copy csproj and restore as distinct layers
WORKDIR /app
COPY *.sln ./
COPY nuget.config ./
COPY API.Core/*.csproj ./API.Core/
COPY API.Core.Service/*.csproj ./API.Core.Service/
RUN dotnet restore
# copy everything else and build app
COPY . .
RUN dotnet publish API.Core/API.Core.csproj -c release -o /app --no-restore
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS final
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "API.Core.dll"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.