Hossein Rahmani
Hossein Rahmani

Reputation: 53

Docker-compose up : no such file or directory, open '/usr/src/app/package.json'

I'm using docker and docker-compose to run my express nodejs api.

Here is my docker file:

FROM node:10-alpine

ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN chmod 755 /usr/src/app

CMD [ "npm", "start" ]

And as I mentioned I'm using docker-compose, here is the docker-compose.yml file content:

version: "3"

services:
  service:
    build: .
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - 3001:3001
    command: npm start

After running docker-compose up, I'm facing an error says it's not able to find package.json.

Here is the error:

service_1  | npm ERR! path /usr/src/app/package.json 
service_1  | npm ERR! code ENOENT 
service_1  | npm ERR! errno -2 service_1  | npm ERR! syscall open 
service_1  | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json' 
service_1  | npm ERR! enoent This is related to npm not being able to find a file. 
service_1  | npm ERR! enoent 
service_1  | 
service_1  | npm ERR! A complete log of this run can be found in: 
service_1  | npm ERR! /root/.npm/_logs/2019-04-17T07_54_07_773Z-debug.log
xuser-api_service_1 exited with code 254

Please help to find my mistake.

Upvotes: 5

Views: 9495

Answers (3)

Maksim
Maksim

Reputation: 1

Extend your build section to this:

build:
  context: MySuperAngularProject
  dockerfile: ./Dockerfile

In context you may set folder with your Angular project with Dockerfile

Upvotes: 0

WSMathias9
WSMathias9

Reputation: 679

you may be using an old image which does not contain latest changes. make sure you using the latest image of your docker file.

docker-compose build 

then run

docker-compose up

if you doing frequent changes to Dockerfile for testing then use.

docker-compose up --build

Upvotes: 1

Muhammad Ali
Muhammad Ali

Reputation: 2014

your working directory is /usr/src/app and you copied the package file on root directory . you have to something like this

# set working directory 
WORKDIR /usr/src/app

# install node_modules
ADD package.json /usr/src/app/package.json
RUN npm install

# copy codebase to docker codebase
ADD . /usr/src/app

Upvotes: 1

Related Questions