3
votes

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?

1
It looks like you don't have node installed, or it isn't in your path. If you just run npm --version does that work? - Andy
@Andy yes, I have node installed. Installed version is 6.9.0. I can run and debug the application locally on my development machine. I am getting the error that I mentioned when I am trying to build the docker container for the application. - anilca

1 Answers

5
votes

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