volumes possibly overwriting npm install
Closed this issue · 1 comments
I am finding that when I go through your solution, when you do npm test which runs docker-compose run --rm nightwatch npm run nightwatch
it creates the docker container and part of the Dockerfile runs RUN npm install --ignore-scripts --unsafe-perm --loglevel warn
. That appears to run OK but where I got tripped up is in your docker-compose.yml file. It has a section in the nightwatch container that mounts the current volume. I find this replaces/wipes out the node_modules directory that was created from the npm install command when the container was created. I am new to all of this but I could be confused but that is what I was experiencing. For now I just removed the volumes section and it is working.
nightwatch: build: . dockerfile: Dockerfile environment: NODE_ENV: test volumes: - .:/usr/src/app
Hello! I apologize for not responding sooner.
You are correct---the .:/usr/src/app
volume is the culprit. Your workaround makes sense. I think when I built this project I must have ran npm install
in the project repo on my native machine and then started the docker container. This would explain why my node_modules remained.
There are two solutions that I know of.
One is to add /node_modules
to this project's .dockerignore file. This will exclude the /node_modules
directory from the mounted .:/usr/src/app
volume.
The other option is to run npm install
on your native host machine, but that feels like a conflict of interest when using Docker to isolate an environment.
Does this help?