Is it possible to ignore a subfolder (e.g. node_module) in the mounted Volume in a docker container?

I am now working on a nodejs project. There are too many small files in the node_modules folder. I want to move a docker-based development environment, so that the node_modules folder can be kept in the docker image (update when necessary). At the same time, I need the source folder of the app remain on the hosting environment. The following is the Docker file, I hoped to work:

FROM node

// 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 in the local node_modules folder it is listed.


No, you can't skip some files when mounting a volume. This is a general Linux (and every other system I know of) limitation, not Docker-related.

However, it's pretty easy to work around it: have a root-level index.js (or whatever) that does nothing but require('./src');. Then have /opt/app be provided by your container and mount /opt/app/src as an external volume.

You could potentially use a bind mount i.e.

mkdir -p /node_modules
mount --bind /node_modules /usr/src/app/node_modules

after the volume declaration but before the npm install.

Need Your Help

Show Limited Number of Page Links at a time in MVC


I am displaying page links with the help of PagedList in MVC. But the issue is if there are 100 pages then all links show at the same time but i want to show 10 links at a time. How can it be

Writing a text file


I am using VB.NET and SQL Server 2005, and I want to write a text file from the database like.