0

I am a very beginner in the Docker world, while I am trying to experiment with Docker file and Docker-Compose I am facing the below error, I now am able to understand it is related to declaring volumes in Docker compose, if I remove volumes, everything works fine, may be it is trying to refer back to the package.json file in my local drive and somehow container is not finding the package.json inside the container, yet to figure out how to solve this.

enoent ENOENT: no such file or directory, open '/app/package.json'

Here is the output from docker-compose:

Starting frontend_web_1  ... done
Starting frontend_test_1 ... done
Attaching to frontend_test_1, frontend_web_1
web_1   | npm ERR! path /app/package.json
web_1   | npm ERR! code ENOENT
web_1   | npm ERR! errno -2
web_1   | npm ERR! syscall open
web_1   | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
web_1   | npm ERR! enoent This is related to npm not being able to find a file.
web_1   | npm ERR! enoent
test_1  | npm ERR! path /app/package.json
test_1  | npm ERR! code ENOENT
test_1  | npm ERR! errno -2
web_1   |
test_1  | npm ERR! syscall open
web_1   | npm ERR! A complete log of this run can be found in:
web_1   | npm ERR!     /root/.npm/_logs/2019-04-22T04_10_39_226Z-debug.log
test_1  | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
test_1  | npm ERR! enoent This is related to npm not being able to find a file.
test_1  | npm ERR! enoent
test_1  |
test_1  | npm ERR! A complete log of this run can be found in:
test_1  | npm ERR!     /root/.npm/_logs/2019-04-22T04_10_39_236Z-debug.log
frontend_web_1 exited with code 254
frontend_test_1 exited with code 254

Dockerfile.dev

FROM node:alpine

WORKDIR /app

COPY package.json .

RUN npm install

COPY . .

CMD ["npm", "run", "start"]

Docker file contents are below

version: '3'
services:
  web: 
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "3000:3000"
    volumes:
      - /app/node_modules
      - .:/app
  test:
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - .:/app
    command: ["npm", "run", "test"]

My directory structure as as shown below,

enter image description here

Executed the below statement and the corresponding response,

$ docker run -it --rm -v "$(pwd):/app" busybox ls -l /app

the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'
  • When you ask a question; please make everything in your power to make it look good. People will just ignore a question that is not properly formatted. devops.stackexchange.com/help/how-to-ask – Kyslik Apr 22 at 10:11
  • Can you try using double quotes in source file name . – Sandeep Chhabra Apr 22 at 13:47
  • Do you have a package.json file in the current directory? Is the drive where your files are saved currently shared to docker (part of the docker preferences) and have you attempted to reset the credentials? Try running docker run -it --rm -v "$(pwd):/app" busybox ls -l /app and show the output (replacing $(pwd) with your current directory if you aren't in a bash shell). – BMitch Apr 24 at 13:03
  • I've edited the question for code formatting and taken my best guess for the indentation of your compose file. Note that whitespace is important in a compose file, so make sure to post that with the same indentation in questions. – BMitch Apr 24 at 13:05
  • Thanks BMitch, I tried to format the docker compose but was not able to to do, I am away from my machine and It will try your solution by tomorrow and post my reply back here. Once again thank you all for your response. – Jophin Michael Apr 24 at 19:34
0

As mentioned in the post/question, it was an issue with volumes, my PC's firewall was blocking the Docker from accessing the drives in my local machine, I reset the credentials in 'Docker for Desktop' app in the shared drives section and everything was back working once again :). Thank you everyone, in fact BMitch was suggesting the same solution, but I was a completely beginner and I did not comprehend it well. Thanks everyone for your responses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.