首页 > 解决方案 > ASP .NET 5.0 React 与 Docker 无法启动“npm”

问题描述

我有一个 .net 5.0 react 应用程序。我正在尝试添加 docker 支持,但我面临以下异常

AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Make sure the executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause.))
System.Threading.Tasks.Task<TResult>.GetResultCore(bool waitCompletionNotification)

InvalidOperationException: Failed to start 'npm'. To resolve this:.

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Make sure the executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause.
Microsoft.AspNetCore.NodeServices.Npm.NodeScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo, string commandName)

这是我的 Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Web/MyApp.Host/MyApp.Host.csproj", "Web/MyApp.Host/"]
COPY ["Data/MyApp.Data.Models/MyApp.Data.Models.csproj", "Data/MyApp.Data.Models/"]
COPY ["Data/MyApp.Data.Common/MyApp.Data.Common.csproj", "Data/MyApp.Data.Common/"]
COPY ["Web/MyApp.Web.Models/MyApp.Web.Models.csproj", "Web/MyApp.Web.Models/"]
COPY ["Data/MyApp.Data/MyApp.Data.csproj", "Data/MyApp.Data/"]
COPY ["MyApp.Common/MyApp.Common.csproj", "MyApp.Common/"]
COPY ["Web/MyApp.Web.Infrastructure/MyApp.Web.Infrastructure.csproj", "Web/MyApp.Web.Infrastructure/"]
COPY ["Services/MyApp.Services.Mapping/MyApp.Services.Mapping.csproj", "Services/MyApp.Services.Mapping/"]
RUN dotnet restore "Web/MyApp.Host/MyApp.Host.csproj"
COPY . .
WORKDIR "/src/Web/MyApp.Host"
RUN dotnet build "MyApp.Host.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.Host.dll"]

我尝试按照Microsoft 的指南进行操作,但它似乎不适用于 5.0。有了它,构建还有另一个例外:

2>#7 0.267 E: Unable to locate package nodejs
2>#7 ERROR: executor failed running [/bin/sh -c apt-get install -y nodejs]: exit code: 100
2>------
2> > [base 4/4] RUN apt-get install -y nodejs:
2>------
2>executor failed running [/bin/sh -c apt-get install -y nodejs]: exit code: 100

有没有人遇到过类似的问题,如何解决?

标签: asp.netdockernpmasp.net5asp.net-spa

解决方案


推荐阅读