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,
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'
Update: 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.
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 runningdocker 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).