Home > Net >  Docker file with asp.net throws npm not found error while it is building in Jenkins
Docker file with asp.net throws npm not found error while it is building in Jenkins

Time:10-16

I am trying to build docker file below through Jenkins.

FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build

ARG PROFILE=Production

WORKDIR /app
COPY . ./

RUN cd src/stayfolio.Demo.Web.aroundfollie \
    && npm install && npm run build:dll && npm start

RUN dotnet restore stayfolio.Demo.Web.sln \
    && cd src/stayfolio.Demo.Web.aroundfollie \
    && mkdir -p build/outputs/aroundfollie \
    && dotnet publish --output ../../build/outputs/aroundfollie/

FROM mcr.microsoft.com/dotnet/sdk:2.1

WORKDIR /app
COPY --from=build /app/build/outputs/aroundfollie ./

CMD ["dotnet", "stayfolio.Demo.Web.aroundfollie.dll"]

However while building the file, it gives an error saying

step 5/10 : RUN cd src/stayfolio.Demo.Web.aroundfollie && npm install && npm run build:dll && npm start ---> Running in 86a2e1e8efcf [91m/bin/sh: 1: npm: not found [0mThe command '/bin/sh -c cd src/stayfolio.Demo.Web.aroundfollie && npm install && npm run build:dll && npm start' returned a non-zero code: 127

as you can see my docker file, I mentioned && npm install && npm run build:dll && npm start, but why the error saying npm: not found?

CodePudding user response:

By default, the docker image mcr.microsoft.com/dotnet/sdk does not have npm installed. You can install it with the package manager or copy it from another docker image.

Example:

FROM node:alpine AS node_base
FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
COPY --from=node_base . .
# the rest of your Dockerfile

This approach is also described in the article you mentioned in your comment How to integrate 'npm install' into ASP.NET CORE 2.1 Docker build

  • Related