【问题标题】:How to dockerize dotnet core angular template application?如何dockerize dotnet core angular模板应用程序?
【发布时间】:2019-06-28 19:30:10
【问题描述】:

我使用 dotnet cli angular 模板创建了一个 Web 应用程序。

dotnet new anguar Web

现在我想 dockerize 这个应用程序。我将以下 Dockerfile 添加到项目文件夹中。

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Web.dll"]

然后当我在项目文件夹中时运行以下命令。

sudo docker build -t accman-web .

但我收到以下错误:

/app/Web.csproj 的恢复在 5.01 秒内完成。 网页 -> /app/bin/Release/netcoreapp2.2/Web.dll 网页 -> /app/bin/Release/netcoreapp2.2/Web.Views.dll /bin/sh:2:/tmp/tmpa49d981806144cfd8e2cbdde42404952.exec.cmd:npm:未找到 /app/Web.csproj(46,5):错误 MSB3073:命令“npm install”退出,代码为 127。 命令“/bin/sh -c dotnet publish -c Release -o out”返回非零代码:1

我必须做些什么来构建这个简单应用程序的映像?

【问题讨论】:

  • 您似乎没有安装节点,或者它不在您的路径中。如果你只是运行npm --version,那行得通吗?
  • @Andy 是的,我已经安装了节点。安装的版本是 6.9.0。我可以在我的开发机器上本地运行和调试应用程序。我在尝试为应用程序构建 docker 容器时遇到了我提到的错误。

标签: angular docker .net-core


【解决方案1】:

Angular 需要 nodejs 和 npm,这似乎是缺失的。将此添加到您的 Dockerfile 以在容器中安装 nodejs 和 npm:

RUN apt-get update && \
    apt-get install -y wget && \
    apt-get install -y gnupg2 && \
    wget -qO- https://deb.nodesource.com/setup_6.x | bash - && \
    apt-get install -y build-essential nodejs

更多详情请参阅this 博文

【讨论】:

猜你喜欢
  • 2017-12-27
  • 2020-12-29
  • 2021-06-18
  • 1970-01-01
  • 2020-02-10
  • 1970-01-01
  • 2021-08-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多