Is it possible to ignore a subfolder (like node_module) on a mounted volume in a docker container?
I am now working on a nodejs project. Too many small files in the node_modules folder. I want to move my docker-level development environment so that the node_modules folder can be stored in the docker image (update if needed). At the same time, I need the original application folder to remain in the hosting environment. The following Dockerfile I was hoping to work:
FROM node
MAINTAINER MrCoder
// To simplify the process node_modules is installed and cached
ADD package.json /opt/app/
WORKDIR /opt/app
RUN npm install
// will be mapped to the local app source folder
VOLUME /opt/app
// This is to test whether local node_modules or the folder in the image is used
CMD ls node_modules
Apparently when I change add any file to my local node_modules folder it is listed.
source to share
No, you cannot skip some files when setting the volume. This is general Linux (and every other system I know of), not Docker-related.
It's pretty easy to get around this though: have a root level index.js
(or whatever) that does nothing but require('./src');
. Then it /opt/app
will be provided by your container and set /opt/app/src
as external volume.
source to share