Docker 构建镜像失败 - 没有这样的文件或目录

kai*_*ite 2 .net linux containers docker dockerfile

我在 Visual Sutdio 2019 中创建了一个 .Net Core 应用程序并添加了 docker 支持,因此它会自动生成文件,但当我构建 docker 映像时,输出显示:

1>/root/.nuget/packages/microsoft.typescript.msbuild/3.9.5/tools/Microsoft.TypeScript.targets(551,5): 
error MSB6003: The specified task executable "node" could not be run. System.ComponentModel.Win32Exception 
(2): No such file or directory [/src/CyberEvalNextGen.csproj]
Run Code Online (Sandbox Code Playgroud)

我认为 COPY 有问题,但我不确定。

这是我的泊坞窗文件:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["CyberEvalNextGen.csproj", ""]
RUN dotnet restore "./CyberEvalNextGen.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "CyberEvalNextGen.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "CyberEvalNextGen.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CyberEvalNextGen.dll"]
Run Code Online (Sandbox Code Playgroud)

Chr*_*ell 5

我遇到过同样的问题。该错误有点误导,因为它在末尾列出了您的 .csproj,但这是关键部分:

The specified task executable "node" could not be run.
Run Code Online (Sandbox Code Playgroud)

它实际上正在寻找运行命令“node”,但找不到可执行文件。为了解决这个问题,我在构建步骤之前添加了 Node.js。

...
WORKDIR "/src/."
#Installing Node.js in build container
RUN apt-get update && apt-get -y install nodejs                   
RUN dotnet build "CyberEvalNextGen.csproj" -c Release -o /app/build
...
Run Code Online (Sandbox Code Playgroud)

这是使用 Linux 容器,但我相信您可以在 Windows 容器中使用 PowerShell 执行类似的操作。