SanketR
SanketR

Reputation: 1192

Dockerfile - npm: not found

I want to create a development environment for a reactjs application. I am new to Docker and have been trying to create an environment using Docker. Below is my Dockerfile code.

# Base node image
FROM node

# create working directory
ADD ./code /usr/src/app
WORKDIR /usr/src/app

# add node_modules path to environment
ENV PATH /usr/src/app/node_modules/.bin:PATH

# copy and install dependencies
COPY ./code/package.json /usr/src/app/package.json
RUN npm install --quiet
RUN npm install [email protected] -g --silent

# start app
# CMD ["npm","start"]

However, I am getting the error "npm: not found" at line RUN npm install --quiet.

Upvotes: 4

Views: 5309

Answers (1)

ErikMD
ErikMD

Reputation: 14723

I confirm that node comes with npm:

$ docker run -it --rm node /bin/bash
root@b35e1a6d68f8:/# npm --version
5.6.0

But the line

ENV PATH /usr/src/app/node_modules/.bin:PATH

overwrites the initial PATH, so you should try replacing it with

ENV PATH /usr/src/app/node_modules/.bin:${PATH}

Also, note that your ADD ./code ... line is clumsy, because it would add all the files of your application (including ./code/package.json!) and this step comes too early (w.r.t. Docker's cache mechanism), so I'd suggest to simply remove that line ADD ./code /usr/src/app and add a line COPY ./code ./ after the RUN npm install ...

Finally you may also want to take a look at the official documentation for "dockerizing" a Node.js app: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/

Upvotes: 8

Related Questions