Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: npm not found

I have the following Dockerfile:

FROM ubuntu
USER root
RUN apt-get update && apt-get install curl -y
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get update && apt-get upgrade -y && apt-get install nodejs -y
RUN mkdir /opt/public
RUN mkdir /opt/bin
ADD public /opt/public
ADD bin /opt/bin
RUN ls -lah /opt/bin
RUN ls -lah /opt/public
ADD run.sh /bin/run.sh
RUN chmod +x /bin/run.sh
RUN cd /opt/bin && npm install
CMD ["/bin/run.sh"]

When I build the Container, I get this eror:

/bin/sh: 1: npm: not found

What is the problem? Could you please help me?

like image 353
Sohrab Avatar asked Mar 20 '19 10:03

Sohrab


People also ask

Why npm is not installing?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

Why is npm install not working on CMD?

You need to make sure you have a package. json file right in the current directory where you run the command. Once you see there's a package. json file in the output as shown above, then you can run the npm install command.


1 Answers

Try installing npm separately while building the image:

RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y nodejs \
    npm                       # note this one
like image 127
Yury Fedorov Avatar answered Sep 23 '22 03:09

Yury Fedorov