6

I'm new to docker and trying to create a container for node apps.

I followed these tutorial, but on docker-compose up I'm getting always these error:

Creating app ... done
Attaching to app
app    | /bin/sh: 1: [“npm”,: not found
app exited with code 127

Here is my Dockerfile:

FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
COPY package-lock.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD ["npm", "start"]

and my docker-compose.yml:

version: "2"
services:
  app:
    container_name: app
    restart: always
    build: .
    ports:
      - "3000:3000"

Has anyone an idea how to fix this error?

Nio
  • 497
  • 3
  • 6
  • 16
  • `“npm”` is not `"npm"`. If you have "smart quotes" in your Dockerfile, it won't parse the string as JSON, so it'll try to run it in the shell -- resulting in the error quoted here. – Charles Duffy Jan 10 '18 at 16:58
  • Pertinent: https://stackoverflow.com/questions/25319631/bash-profile-aliases-command-not-found – Charles Duffy Jan 10 '18 at 17:00

1 Answers1

23

You have the wrong quotes in your dockerfile:

app    | /bin/sh: 1: [“npm”,: not found

doesn't match the quotes in the example you pasted:

CMD ["npm", "start"]

Double check your Dockerfile to correct your quotes.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • I'm split on whether to close this as a duplicate of a question with someone using smart quotes vs regular quotes in a slightly different context. – Charles Duffy Jan 10 '18 at 17:01
  • @CharlesDuffy I'd be fine marking it as a dup of this: https://stackoverflow.com/questions/44077815/dotnet-docker-bin-sh-1-dotnet-not-found . If you flag it, I'll second it (my vote is binding on the docker tag so don't want to take a unilateral action). – BMitch Jan 10 '18 at 17:04
  • I had already replaced the brackets, but I had to run `docker-compose up --force-recreate` to apply the changes – Nio Jan 10 '18 at 17:33
  • 1
    I do not remember anywhere reading that double quotes are needed. I was using `CMD ['npm', 'start']` and getting the same error. This is fixed by changing to double quotes. – justin Dec 01 '21 at 21:10