2

i will docker my app js. I run the order docker-compose up. But i have error : app | /bin/sh: 1: [: “npm”,: unexpected operator.

Dockerfile

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

docker-compose.yml

version: "2"
services:
app:
  container_name: app
  restart: always
  build: .
  ports:
    - "3000:3000"
  links:
    - mongo
mongo:
  container_name: mongo
  image: mongo
  volumes:
    - ./data:/data/db
  ports:
    - "27017:27017"

2 Answers 2

8

Double-check your Dockerfile.

"npm" is different from “npm”, notice the double quote " and . You should always use " (input from your keyboard) rather than

then run the following command:

docker-compose up --build
Sign up to request clarification or add additional context in comments.

2 Comments

i edit my Docker file with CMD [ “npm“, “start“ ] and l have same error
You should remove all unnecessary whitespace in Dockerfile, try with this Dockerfile (Ctrl + A your file and replace with this) pastebin.com/raw/Dzu6KPYD Then run docker-compose up --build
0

You could use the CMD instruction instead of RUN.

Change this line:

RUN ["npm", "start"]

...to this:

CMD ["npm", "start"]

The CMD instruction is triggered when your container starts.

Docs here: https://docs.docker.com/engine/reference/builder/#cmd

I hope this helps.

Comments

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.