Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npm not found when running docker container from node image

# Dockerfile
FROM node:7-alpine
RUN mkdir -p /src/app
WORKDIR /src/app
COPY package.json /src/app/package.json
RUN npm install
COPY . /src/app
EXPOSE 3000
CMD ['npm', 'start']

I'm trying to complete a katacoda.com exercise for Dockerizing nodejs applications with the Dockerfile above. The build completes but running the image quits immediately and in the docker logs I see:

/bin/sh: [npm,: not found

I tried running the container in interactive mode with docker -it nodeapp /bin/bash which raised the error docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory". So I'm not sure what is going on here.

like image 935
Peter Avatar asked Aug 26 '17 14:08

Peter


People also ask

Does node docker image include npm?

No, it doesn't come with npm. You'd want to use one of the node images such as github.com/nodejs/docker-node/blob/… which has an alpine base image but comes with npm.


1 Answers

The reason it doesn't work is single quotes

CMD ['npm', 'start']

should be

CMD ["npm", "start"]

When you don't use double quotes, docker will remove the single quotes and process the command as [npm, start]

That is why you see error [npm, : not found

like image 154
Tarun Lalwani Avatar answered Oct 12 '22 16:10

Tarun Lalwani