admin管理员组

文章数量:1394520

I have added Dockerfile in the react project and run this mand docker build . -t *image name*.My build was success.But when I start to run my image (docker run *imagename*) I got this error /bin/sh: [npm: not found.I have attached my Dockerfile details below:

FROM node:alpine
WORKDIR '/app'

COPY package.json .
RUN npm install
COPY . .
CMD ["npm" "start"]

Anyone help me with this error?

I have added Dockerfile in the react project and run this mand docker build . -t *image name*.My build was success.But when I start to run my image (docker run *imagename*) I got this error /bin/sh: [npm: not found.I have attached my Dockerfile details below:

FROM node:alpine
WORKDIR '/app'

COPY package.json .
RUN npm install
COPY . .
CMD ["npm" "start"]

Anyone help me with this error?

Share Improve this question asked Sep 4, 2020 at 15:41 DineshDinesh 251 silver badge5 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

I would revise the Dockerfile with the following:

FROM node:alpine
WORKDIR /app

COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]

In case this helps anyone else,

FROM node:15.13-alpine

WORKDIR /code/

#mapping environment path for node modules
ENV PATH="./node_modules/.bin:$PATH"

COPY package.json yarn.lock /code/
# COPY package-lock.json /code/

RUN npm install

#adding the rest of the client code 
COPY . /code/

EXPOSE 3000

CMD ["npm", "start"]

All i had to do to solve this error was change the first line. Change WORKDIR /code/ to /code

The accepted answer covers it but it is easy to miss, as the answer mainly focuses on changing the last line which was not the case for me.

I had the same isssue, then followed the node js document and updated my Dockerfile and problem resolved;

Before:

FROM node:16-alpine

COPY . . 
RUN npm i

CMD ['npm', 'start']

After:

FROM node:16-alpine

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm ci --only=production

COPY . . 
EXPOSE 8080
CMD ['npm', 'start']

# or CMD ['node', 'server.js']
# both works

本文标签: javascriptI am getting binsh npm not found error while executing the react image in DockerStack Overflow