0

I am trying to share my local space with my docker container with Volume. BTW I am working on a nest app. The problem is whenever I am trying to enable the volume feature I am getting some weird error!

api_1  | npm ERR! code ENOENT
api_1  | npm ERR! syscall open
api_1  | npm ERR! path /usr/app/package.json
api_1  | npm ERR! errno -2
api_1  | npm ERR! enoent ENOENT: no such file or directory, open '/usr/app/package.json'
api_1  | npm ERR! enoent This is related to npm not being able to find a file.
api_1  | npm ERR! enoent 
api_1  | 
api_1  | npm ERR! A complete log of this run can be found in:
api_1  | npm ERR!     /root/.npm/_logs/2020-05-24T19_44_36_593Z-debug.log

I am calling this weird because I haven't found any proper explanation about this error. although these links are quite close to my problem prob1, prob2

My docker file -

# Download base image
FROM node:alpine

# Define Base Directory
WORKDIR /usr/app

# Copy and restore packages
COPY ./package*.json ./
RUN npm install

# Copy all other directories
COPY ./ ./

# Setup base command
CMD [ "npm", "run", "start" ]

and my docker-compose file

version: '3'
services: 
   api:
     build:
        context: .
        dockerfile: Dockerfile.dev
    ports : 
        - "4200:4500"
    volumes:
        - /usr/app/node_modules
        - /:/usr/app

as far as I can understand whenever I tried to use volume means /:/usr/app replacing docker directory with local project directory. But on my project root directory, I have package.json file. Also in my docker file, I have copied package.json file.

can anyone help me with this issue? I am new with docker, I am doing this just for learning purpose.

Amjad
  • 316
  • 4
  • 20
  • In your `docker-compose`file, you are mounting your host `/` to `/usr/app`? Are you really sure that it is what you intended? Didn't you intended to do `- ./:/usr/app` rather? – β.εηοιτ.βε May 24 '20 at 20:43
  • This said, mind that when you bind mount (via `volumes`), a host folder to a container folder, you are totally overwriting the full container folder. So any file you would have copied at the build time is just gone. – β.εηοιτ.βε May 24 '20 at 20:45
  • Whenever i tried to add `.` or `./` i got another error. That's why i add `/`. – Amjad May 24 '20 at 20:47
  • What's the need of mounting `/:/usr/app`? As you are already `COPY ./ ./` in the container? – nischay goyal May 24 '20 at 20:50
  • I also tried to just map `SRC` folder but then got `typescript` config missing error – Amjad May 24 '20 at 20:50
  • Because as my intention to work as dev env. I mean when i will change anything to project dir, i want that to also be reflected to container – Amjad May 24 '20 at 20:52

0 Answers0