title: Writable node_modules with read only source files in docker
body: <p>My <code>webapp/Dockerfile</code> looks like this:</p>
  
  <pre><code>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"]
  </code></pre>
  
  <p>I want to allow the app to be able to read the source code and also write into sub-folders like <code>node_modules</code>, but I don't want those changes to come in my local machine. Hence, I have two choices:</p>
  
  <ol>
  <li>Change <code>--prefix='/tmp'</code> in <code>node install</code> and mount the src as <code>ro</code></li>
  <li>Copy <code>COPY</code> the src and then the container can write wherever it wants. </li>
  </ol>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>sudo docker-compose down &amp;&amp; sudo docker-compose up --build -d
  </code></pre>
  
  <p>But the COPY command is cached by docker and won't be updated, even after file changes.</p>
  
  <hr>
  
  <p><strong>TL;DR:</strong> 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'.</p>