I have the following in my docker-compose.yml file:
volumes:
- .:/var/www/app
- my_modules:/var/www/app/node_modules
I do this because I don't have node_modules on my host and everything gets installed in the image and is located at /var/www/app/node_modules.
I have two questions regarding this:
An empty folder gets created in my host named
node_modules. If I add another volume (named or anonymous) to the list in my.ymlfile, it'll show up in my host directory in the same folder that contains my.ymlfile. From this answer, it seems to have to do with the fact that there's these two mappings going on simultaneously. However, why is the folder empty on my host? Shouldn't it either a) contain the files from the named volume or b) not show up at all on the host?How does Docker know to check the underlying
/var/www/app/node_modulesfrom the image when initializing the volume rather than just saying "Oh,node_modulesdoesn't exist" (since I'm assuming the host bind mount happens before the named volume gets initialized, hence/var/www/appshould no longer have a folder namednode_modules. It seems like it even works when I create a samplenode_modulesfolder on my host and a new volume while keepingmy_modules:/var/www/app/node_modulesβit seems to still use thenode_modulesfrom the image rather than from the host (which is not what I expected, although not unwanted).