Local Node_Modules in Dockerized RedwoodJS

I created a dockerized RedwoodJS (Version 7.0.3) application. I noticed that inside the docker-compose.dev.yml there is a named volume node_modules. From my understanding during the build phase in the Dockerfile during base the node_modules are installed and because the location is the same as in the named volumes mount node_modules:/home/node/app/node_modules they are persisted between container starts as they are never copied from one stage to the other (expect the .prisma folder).
This is fine and works, but when developing with a IDE (vscode in my case) it cannot find the node_modules because they are never installed locally.

To solve this one could perform the yarn install locally, but I don’t think this is a good solution as it now requires someone to have node installed locally, and version missmatch hell will open wide up (e.g. switching between projects with different node version etc.)

Is there a solution where I can have this named volume also mounted locally with the mounted volume declaration - .:/home/node/app or is there something else I’m missing?

Hi @waffle and thanks for the question about Redwood and Docker. I’d ask if @Josh-Walker-GM or @dom cN help as they are much more experienced with Docker than I am.

Yes I would appreciate the help, in the meanwhile I tried the following:

volumes:
  node_modules:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: './node_modules'

This achieved something wierd, after pruning my local docker-containers and volumes, rebuilding without cache, and starting directly (docker-compose -f docker-compose.dev.yml run redwood bash) I noticed that a few node_modules were installed (10-15), after exiting and reentering it would grow everytime by about 5-10 new modules.
So when starting it still complains that some modules are missing.
Really wierd wodo behaviour, don’t really understand why this is happening :sweat_smile:

It seems that I got the behaviour that I asked for with the above command, but in order for it to work, the mounting point has to exist and has to be completly empty so no .gitignore in order to track the folder.
A developer has to manually create the dir with mkdir befor starting it the first time.
Also it seems that when starting with docker compose -f docker-compose.dev.yml up it will take a while since it’s copying around 80k files totaling in about 550 MB of data. Seems wierd that it’s not just mounting it directly but rather just copies the files but I have no deeper knowledge into docker explaining why it does that or how to fix that.
Maybe one of you guys understands a bit better whats happening under the hood here or has a better solution, but until them I guess im stuck with this approach.