ASP .NET 5.0 React with 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 的 this 指南,但它似乎不适用于 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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)