docker shared volume

i am facing issue while re-using global node_modules inside my container ,
my requirement is , i want to use my older npm’s inside my container by sharing the volumes where my global node_modules are present… i have tried most of the approaches but still i cant able to re-use my global npms inside the containers…

image: mongo

  • "27017:27017"
    restart: always
    build: .
  • ./:/app
  • ./node_modules:/usr/local/lib/node_modules
  • "6000:6000"
  • db
    command: node /app/index.js

This is my docker-compose file.

Having your application depending on code and especially shared libraries injected by the host is not a best practice.

That’s very easy to accomplish. Put an appropriate version constraint in your package.json file. Both npm and yarn have a “lock” file that names very specific versions of the packages that will be installed. Then a routine Dockerfile will work for you, something like

FROM node:8 
COPY package.json yarn.lock .
RUN yarn install
COPY main.js src .

Each image will have its own node_modules tree, just like each source directory in your developer workspace will have its own node_modules tree.

If your volume driver accepts a comma-separated list as an option, you must escape the value from the outer CSV parser. To escape a volume-opt , surround it with double quotes ( " ) and surround the entire mount parameter with single quotes ( ' ).MyBKExperience – Burger King Feedback and Survey