I am using the latest Docker public beta on Windows 10.
I am developing a Node.js app and I am using Docker with my src directory mounted as a volume in a container.
I cannot run npm install
from inside the container because it will cause the creation of symbolic links (in the node_modules directory), that apparently are not supported in volumes if the host is Windows.
Is there anything I can do to solve this problem?
I have no issues on running this in a Linux environment.
After some research I found many solutions involving Virtualbox, being for the "old" version of Docker (Docker Toolbox).
I solved in the following way.
I'll use /usr/src
as the directory to mount to in the container in this example:
/usr/src
: -v /path/to/src:/usr/src
node_modules
: -v /usr/src/node_modules
In this way you will have that /path/to/src
will be mounted to /usr/src
and /usr/src/node_modules
will be mounted as a data volume.
The final result is that the even though a node_modules
directory is created on the host, it will stay empty.
This solution exploits Docker Data Volumes.
This is applicable every time you want to avoid that changes in a subdirectory of a mounted directory to be reflected on the host, not just for node_modules
.
To avoid symlink
error with NPM you can use command:
npm install --no-bin-links
However, to absolutely avoid symlink
issue, you should not set your nodejs project in the mounted directory (mounted from Window)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With