Skip to content
Advertisement

My container isn’t finding the package.json to execute npm install on docker-compose

I’m trying to deploy an application using docker-compose and the app is in a folder in the host machine (in the same dir that the docker-compose file).

I’m runnig the command docker-compose up -d, however, it seems that the volume isn’t mounting because when the command npm install is executed the following message is displayed:

Step 3/4 : RUN npm install
 ---> Running in a09b1e8139ae
npm WARN saveError ENOENT: no such file or directory, open '/app/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/app/package.json'
npm WARN app No description
npm WARN app No repository field.
npm WARN app No README data
npm WARN app No license field.

After that my container is exited.

My files:

docker-compose.yml

version: '3'

services:
  github-app:
    build:
      context: ./docker
    volumes:
      # Place app files.
      - ./:/app
    ports:
      - "3000:3000"

docker/Dockerfile

FROM node:10.15.1

WORKDIR /app
RUN npm install
CMD ["npm", "start"]

Does anybody know what I’m doing wrong?

Advertisement

Answer

Unless i am mistaken. the docker directory that responsible for the build process will be executed before mounting any volumes so the image during the build wont have any thing called package.json because its outside the context directory. try to move the dockerfile to the same root directory where you have docker-compose.yml and package.json and update the dockerfile with

COPY . /app

Instead of depending on the mounted volumes at it wont be available until the build is done

Advertisement