14
# 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.

7
  • try docker -it nodeapp sh and then which npm to see if npm is installed or not Commented Aug 26, 2017 at 14:05
  • because alpine doeesn't have bash hence the above error. try with sh and check npm later once you're in Commented Aug 26, 2017 at 14:06
  • thanks @TuanAnhTran docker -it nodeapp sh works and npm is installed and npm start works Commented Aug 26, 2017 at 14:13
  • so how come docker run .... doesn't? Commented Aug 26, 2017 at 14:14
  • 2
    i changed it to CMD npm start and it works now. Commented Aug 26, 2017 at 14:22

3 Answers 3

37

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

Sign up to request clarification or add additional context in comments.

Comments

6

I had the same symptom but the problem was slightly different. Writing here in case google leads others in my situation to this link For me the issue was forgetting commas in the CMD. So the solution was going from CMD ["npm" "start"] to CMD ["npm", "start"].

1 Comment

i can't believe myself i did this silly mistake
1

i changed CMD ["npm", "start"] to CMD npm start, with no " or ' special characters. it works now

1 Comment

Same here with podman-machine on MacOS Sonoma.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.