简体   繁体   中英

How to dockerize dotnet core angular template application?

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

dotnet new anguar Web

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 .

But I am getting the following error:

Restore completed in 5.01 sec for /app/Web.csproj. 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

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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