简体   繁体   English

如何通过docker化dotnet核心角度模板应用程序?

[英]How to dockerize dotnet core angular template application?

I created a web application using the dotnet cli angular template. 我使用dotnet cli角度模板创建了一个Web应用程序。

dotnet new anguar Web

Now I want to dockerize this application. 现在,我想对这个应用程序进行dockerize。 I added the following Dockerfile to the project folder. 我将以下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"]

And then run the following command when I am in the project folder. 然后,当我在项目文件夹中时,运行以下命令。

sudo docker build -t accman-web .

But I am getting the following error: 但是我收到以下错误:

Restore completed in 5.01 sec for /app/Web.csproj. /app/Web.csproj的恢复在5.01秒内完成。 Web -> /app/bin/Release/netcoreapp2.2/Web.dll Web -> /app/bin/Release/netcoreapp2.2/Web.Views.dll /bin/sh: 2: /tmp/tmpa49d981806144cfd8e2cbdde42404952.exec.cmd: npm: not found /app/Web.csproj(46,5): error MSB3073: The command "npm install" exited with code 127. The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1 Web-> /app/bin/Release/netcoreapp2.2/Web.dll Web-> /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? 我需要做什么来构建这个简单应用程序的映像?

You need nodejs and npm for Angular, which seems to be missing. 您需要Angular的nodejs和npm,这似乎丢失了。 Add this to your Dockerfile to install nodejs and npm in the container: 将此添加到您的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

See this blog post for more details 请参见博客文章了解更多详情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM