I’m trying something that I expected to be pretty straightforward but have run into a problem I don’t know the answer to.
I’m running a dev container (the same as my CI container) to be able to have repeatable builds locally during development. I also want it to be possible to run build commands locally on my Mac and have that work too. The sticking point right now is node_modules. I want the node_modules on my Mac and the node_modules in the container to be completely separate so that I don’t run into build issues. Here is the command I’m using to start my dev container:
docker run -d \ --name $NAME \ -v /var/run/docker.sock:/var/run/docker.sock \ --mount type=volume,source=code-node,destination=/code/node_modules/ \ --mount type=bind,source="$(pwd)",destination=/code \ -w /code \ ci-container \ tail -f /dev/null
This works as I’d expect, at first. I can run web pack in the container and it will build the frontend correctly without messing with the Mac node_modules.
However, if on my Mac I run
touch node_modules (which gulp seems to do) then the mounted volume disappears from the container, and running
docker exec ls node_modules shows that node_modules in the container has become the same as the one on my Mac.
What’s going on? How can I have the behavior I want? Will it behave any differently if run via docker-compose? I’m at a loss for why my volume disappears in this way.