【发布时间】:2020-04-16 01:00:22
【问题描述】:
我正在尝试创建一个 Angular/.NET Core webapp 并使用 Docker 提供它。我为项目使用了 VS 模板及其“添加 Docker 支持”功能。
我能够将 npm 添加到 Dockerfile,但现在尝试安装 npm 时似乎仍然失败。
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["MeMa/MeMa.csproj", "MeMa/"]
RUN dotnet restore "MeMa/MeMa.csproj"
COPY . .
WORKDIR "/src/MeMa"
RUN dotnet build "MeMa.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MeMa.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MeMa.dll"]
在最后的发布步骤中似乎在日志中失败了:
1>Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> Restore completed in 42.19 ms for /src/MeMa/MeMa.csproj.
1> MeMa -> /src/MeMa/bin/Release/netcoreapp3.1/MeMa.dll
1> MeMa -> /src/MeMa/bin/Release/netcoreapp3.1/MeMa.Views.dll
1> /bin/sh: 2: /tmp/tmp9ba7ec2b1c554866b53e549fed3d16b4.exec.cmd: npm: not found
1>/src/MeMa/MeMa.csproj(48,5): error MSB3073: The command "npm install --verbose" exited with code 127.
1>Removing intermediate container 4ac7db87ff52
1>The command '/bin/sh -c dotnet publish "MeMa.csproj" -c Release -o /app/publish' returned a non-zero code: 1
1>c:\users\wkara\source\repos\mema\mema\dockerfile : error CTC1014: Docker command failed with exit code 1.
1>c:\users\wkara\source\repos\mema\mema\dockerfile : error CTC1014: The command '/bin/sh -c dotnet publish "MeMa.csproj" -c Release -o /app/publish' returned a non-zero code: 1
1>Done building project "MeMa.csproj" -- FAILED.
所以它似乎在 npm install 任务上失败了,这反过来又导致整个构建失败。
这是我的 .csproj 文件中的引用行。
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> **// This is line 48**
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
那么,是否存在某种目录问题,是否试图在错误的位置运行 npm install ?这是我的目录结构:
【问题讨论】:
标签: node.js docker .net-core build