My webapp/Dockerfile
looks like this:
FROM project_base-container
EXPOSE 9100
# ...
# Using copy instead of mount, since we need to write in sub-directories like node_modules etc.
COPY . /usr/src/app/webapp
CMD ["bash", "webapp/scripts/build_and_run.sh", "setup_deps_and_run_app"]
I want to allow the app to be able to read the source code and also write into sub-folders like node_modules
, but I don't want those changes to come in my local machine. Hence, I have two choices:
- Change
--prefix='/tmp'
innode install
and mount the src asro
- Copy
COPY
the src and then the container can write wherever it wants.
Solution 1 wrecks havoc, because now I have to copy/link all files like package.json, index.html etc to the prefix location. Solution 2 is what I have done above.
When I use COPY everything is fine for the first time. But now the problem is that after changes in source code, I want to update the source code in the image every time I do:
sudo docker-compose down && sudo docker-compose up --build -d
But the COPY command is cached by docker and won't be updated, even after file changes.
TL;DR: I have a src folder 'webapp' that I want to mount from host as readonly, but my app wants to write to a subfolder 'webapp/node_modules'.