Search code examples
node.jsdockernpm-installpackage.jsondocker-volume

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


I'm using Docker using Docker Toolbox because of I have Windows Home. I made a React application using:

npx create-react-app frontend

Thus I made a "Dokerfile.dev" file in which I say doicker to use base image node alpine version, setting working directory "/app", to copy "package.json" that needs to install node "run npm install", and then I say to copy the other files. I put also the command to be enable when I start that container:

FROM node:alpine

WORKDIR '/app'

COPY package.json .
RUN npm install
COPY . .

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

And seems work, because of if I build:

docker build -f Dockerfile.dev .

and run it mapping container port to local port (3000):

docker run -it -p 3000:3000 [containerID]

it works on http://192.168.99.100:3000, react page working.

After that, I wanna try to run using volume. Actually I delete node_modules dependency from "app" folder, because of npm install it double. This I put it like a placeholder. Instead, I map the Present Working Directory (pwd) with "/app":

docker ruyn -it -p 3000:3000 -v /app/node_modules -v /c/Program\ Files/Docker\ Toolbox/frontend:/app -e CHOKIDAR_USEPOLLING=true a631964d87b2

(my pwd contains whitespaces, thus I have to use "\ " isntead of "". "a631964d87b2" is my container id)

The result is:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-23T20_10_26_143Z-debug.log

Why it works without Volume, instead using volume it says that it doesn't found /app/package.json? That's impossible because of in Dockerfile.dev I say:

COPY package.json .

thus to copy package.json to the current working directory which is "/app".

enter image description here

--- UPDATE

Actually it works if I move project inside c:/Users/username

and I text this:

docker run -it -p 3000:3000 -v /app/node_modules -v $(pwd):/app -e CHOKIDAR_USEPOLLING=true a631964d87b2  

That's because $(pwd) puts my Present Working Directory, and in that case it doesn't have whitespaces inside it. How I can put my plan working directory with namespaces?

--- UPDATE 2

problem are not whitespaces: I tried to modify c:/Users/username/frontend in c:/Users/username/abc\ frontend

and it still works. It seems that project must be in users and not in program files ?


Solution

  • The problem was that project was outside Window Users folder, in fact it was in Program Files. Trying to move it in Users/myUser, it works also using a path with whitespaces