#Docker setup issue

29 messages · Page 1 of 1 (latest)

tawdry granite
#

Hey!
Im not sure if this is the right place to ask about this but I have a problem with my current docker setup, more specifically related to installing npm packages.

https://pastebin.com/LFF8saqE
This is my docker compose atm.

The current issue is everytime I try to install a new package (for example docker exec -it backend bash && npm i whatever) the changes dont show up on the host machine. They only show up in the docker container. And VSCode obviously wont see that there are new modules in my mounted node modules.

Is there a way to make it so i dont have to docker compose down and up everytime I install a new package?
Its really frustrating 😭

Thanks a lot in advance and if its not the right place to ask about this im sry!

slow coral
#

can i see your repo ?

tawdry granite
#

ye give me a sec i need to unprivate it

tawdry granite
#

its completely empty rn, only the prettier/eslint/husky setup is done

warm vortex
#

You are not mounting the /app/node_modules to any particular physical path on the machine, so docker is mounting it into a random directory

You need both the host mount path and the container mount path:
/somewhere/node_modules:/app/node_modules

tawdry granite
#

i tried without it and node_modules was still empty on host machine

warm vortex
#

You shouldn't need to. But if you do, maybe there's some aliasing shenanigans going on

tawdry granite
#

this is how ive done it before and this one works

#

but i refuse to write a .sh file for an npm run dev

#

i have no idea why i cant replicate how it works without it

warm vortex
#

Honestly I have no idea, but why exactly do you need node_modules to be accessible on the host machine?

#

You can probably do with a named volume instead of mointing it to a specific path

tawdry granite
#

frontend/backend works as expected but vscode looks for dependencies in local environment

warm vortex
#

I see, so it's a setup for dev, too.

#

You should be able to mount it with - ${PWD}/node_modules:/app/node_modules

#

It needs a full path to the folder on your machine

tawdry granite
warm vortex
#

If the path is ./packages/backend/node_modules, then I also have no idea why it wouldn't work

tawdry granite
#

ill delete every single volume/image/container

#

and check in 10mins

#

in theory it should work

warm vortex
#

It definitely should 🤔

slow coral
#

i have no idea too, seem you need to create a .sh file to do same way 😅

i think why you can replicate is different way its work, maybe like this:

  • Without .sh: run the project from built image
  • With .sh: run the .sh (npm run dev) on your mount folder
tawdry granite
#

i fixed it. Its not pretty but it works

#

somehow my local node_modules was being overwritten and thats why it was empty