Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker volumes and package.json not found

Tags:

node.js

docker

I m learning docker and I m having some troubles dealing with volume on a nodejs application.

Actually, I have a simple application that I want to test each time I restart my container.

This way, I have the following dockerfile :

FROM node:4-onbuild

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

CMD [ "npm", "test" ]

Now, I have built the image using :

docker build -t myapp .

And I tried to run it using the followings scripts :

docker run -v //c/Project/nodejs/my-app:/usr/src/app my-app

or

docker run -v /c/Project/nodejs/my-app:/usr/src/app my-app

or even

docker run -v c:/Project/nodejs/my-app:/usr/src/app my-app

I have the following error that tells me that I don't have a package.json file inside of /usr/src/app (but it's where my volume is located, it should be right no ?)

npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm ERR! Linux 4.4.15-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "test"
npm ERR! node v4.5.0
npm ERR! npm  v2.15.9
npm ERR! path /usr/src/app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/app/npm-debug.log

NB : if I use the COPY command instead of volumes, it works great, and I can see my nodejs tests inside of the docker container

NB2 : I m on windows 10, docker v1.12.0

like image 855
mfrachet Avatar asked Aug 18 '16 12:08

mfrachet


1 Answers

Docker for Windows runs in a VM that runs your containers inside (it still needs a Linux Host). When you mount a host volume, that volume is mounted on the Linux host. The only directory that is mounted from the Linux VM to the parent Windows OS is c:/Users, which is visible as /c/Users in the VM (see docker's volume tutorial). Move your project to a directory under Users and mount that.

The reason for the empty folder/missing file is that this is the default when you mount a non existent host folder/file into a container. And in your case, /c/Project does not exist in the VM. The COPY works because doing a build sends over the current folder (with the exception of .dockerignore entries) to the Docker engine (running in the VM) before the build begins. This is transmitted over the API rather than doing a volume mount.

like image 156
BMitch Avatar answered Sep 29 '22 18:09

BMitch