I want to run a react app in a docker container with the help of a docker-compose and docker file. It is showing package.json file is missing but I do have that file in my local directory which I am trying to map with the docker container.
I have successfully built the image by running docker-compose build
command. But while I am trying to run docker-compose up
command it is showing below error
PS E:\Project\MyProfile\my-profile> docker-compose up
Starting myprofile_web_1 ... done
Attaching to myprofile_web_1
web_1 | npm ERR! code ENOENT
web_1 | npm ERR! syscall open
web_1 | npm ERR! path /app/package.json
web_1 | npm ERR! errno -2
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
web_1 |
web_1 | npm ERR! A complete log of this run can be found in:
web_1 | npm ERR! /root/.npm/_logs/2020-06-03T16_54_28_610Z-debug.log
myprofile_web_1 exited with code 254
My machine is Windows 10 and let me know if you all need any further information.
My Docker File:
FROM node:alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm","run","start" ]
Docker Compose File:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- 3000:3000
volumes:
- /app/node_modules
- .:/app
UPDATE 1:
As Peter suggested I look into 'app' directory in the Docker container I can see package.json file there.
Update 2
File Permissions log
PS E:\Project\MyProfile\my-profile> docker run website ls -lah
total 724K
drwxr-xr-x 1 root root 4.0K Jun 6 16:03 .
drwxr-xr-x 1 root root 4.0K Jun 6 16:07 ..
-rwxr-xr-x 1 root root 17 Jun 5 16:55 .dockerignore
drwxr-xr-x 7 root root 4.0K Apr 20 16:02 .git
-rwxr-xr-x 1 root root 310 Oct 26 1985 .gitignore
drwxr-xr-x 2 root root 4.0K Apr 18 10:53 .vscode
-rwxr-xr-x 1 root root 190 Jun 4 18:08 Dockerfile.dev
-rwxr-xr-x 1 root root 52.6K Sep 21 2019 MyProfile.png
-rwxr-xr-x 1 root root 2.8K Oct 26 1985 README.md
drwxr-xr-x 3 root root 4.0K Apr 16 17:34 build
drwxr-xr-x 3 root root 4.0K Oct 2 2019 config
-rwxr-xr-x 1 root root 274 Jun 4 17:54 docker-compose.yml
-rwxr-xr-x 1 root root 610 Apr 24 05:11 eg.js
drwxr-xr-x 1056 root root 36.0K Jun 6 15:59 node_modules
-rw-r--r-- 1 root root 562.9K Jun 6 15:59 package-lock.json
-rwxr-xr-x 1 root root 3.8K Apr 5 08:34 package.json
drwxr-xr-x 2 root root 4.0K Apr 20 05:03 public
drwxr-xr-x 2 root root 4.0K Oct 2 2019 scripts
drwxr-xr-x 6 root root 4.0K Apr 15 16:44 src
Solution:
I was able to resolve this issue by moving my Project to C:/User/{User_Name} folder. Explaination for the same can be found here (Docker volumes and package.json not found)
If you do not want to move folders just like me you can do that as well checkout this (How to mount local volumes in docker machine)