本文介绍了如何dockerize dotnet核心角度模板应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a web application using the dotnet cli angular template.

dotnet new anguar Web

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

Now I want to dockerize this application. I added the following Dockerfile to the project folder.

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"]

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

And then run the following command when I am in the project folder.

sudo docker build -t accman-web .

但我收到以下错误:

/app/Web.csproj 的恢复在 5.01 秒内完成.Web ->/app/bin/Release/netcoreapp2.2/Web.dllWeb ->/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

我需要做什么来构建这个简单应用程序的映像?

What do I have to do to build the image of this simple application?

推荐答案

你需要 nodejs 和 npm for Angular,这两个似乎缺失了.将此添加到您的 Dockerfile 以在容器中安装 nodejs 和 npm:

You need nodejs and npm for Angular, which seems to be missing. Add this to your Dockerfile to install nodejs and npm in the container:

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

参见 这篇博文了解更多详情

See this blog post for more details

这篇关于如何dockerize dotnet核心角度模板应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:06