skip to Main Content

enter image description here

When using bind mounts or anonymous volumes, the node_modules folder is created on the host machine, but is n’t the node_modules must be created inside the container?

when I run this command node_modules folder is created on my machine inside the project folder.

here is cmd:

docker run -p 3000:80 -d --name feedback-app -v feedback:/app/feedback -v "/home/rohan/Documents/DockerTut/03 - Managing Data & Working with Volumes/003 data-volumes-01-starting-setup/data-volumes-01-starting-setup:/app:ro"  -v /app/node_modules -v /app/temp feedback-node-app:volumes

2

Answers


  1. To avoid this, you can either ensure that the node_modules directory exists on the host machine at the specified mount point before starting the container, or you can include logic in your Dockerfile or entrypoint script to handle the presence or absence of the node_modules directory as needed.

    Login or Signup to reply.
  2. You have done everything you can do. You already have this:

    -v "$(PWD):/app" -v /app/node_modules

    That is, you are mounting your current folder at /app AND creating a tmpfs mount at /app/node_modules.

    Because you have mounted /app to your current working dir, anything created in it is going to be visible locally.
    This means that the node_modules anchor folder will be visible.
    However, mounting a tmpfs on node_modules ensures that any files created in by the container in node_modules are not visible on the host AND ensures that any host specific contents are not visible in the container.

    Well. There is a way to avoid node_modules and that is to convert to docker compose and its watch functionality. This requires that you use a Dockerfile to pre-populate the image and then "watch" will sync any changes on the host to the container.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search