I use docker-compose (version 1.24.0) to run my Node.js App inside a container. In development mode I mount my src volume, but I'd like the container to use a node_modules directory that is not created on my host, just locally within the container.
Excerpt from my docker-compose
volumes:
  - .:/usr/src/app
command:
 - /bin/sh
 - -c
 - |
   npm install
   npm run dev
Is there a way to make the sub-directory /usr/src/app/node_modules local to the container and have npm install not create and populate the directory ./node_modules on the host?
I tried this solution posted on Stackoverflow, somehow the directory node_modules still gets created and populated on my host upon running npm install . inside the container. I used the following modified docker-compose.yml:
volumes:
  - .:/usr/src/app
  - /usr/src/app/node_modules
command:
 - /bin/sh
 - -c
 - |
   npm install
   npm run dev
I even tried using named volumes like so:
  volumes:
    - .:/usr/src/app
    - node_modules:/usr/src/app/node_modules
volumes:
- node_modules
Help will be much appreciated.