title: docker-compose only mount files that exist on host to container
body: <p>Is it possible to to mount a host directory in to a container but only allowing overwriting files that exist on the host?</p>
  
  <p>Example github repo: <a href="https://github.com/UniBen/stackoverflow-59031249" rel="nofollow noreferrer">https://github.com/UniBen/stackoverflow-59031249</a></p>
  
  <p>E.g
  Host:</p>
  
  <pre><code>src/
    public/
      index.php (200kb)
  </code></pre>
  
  <p>Container:</p>
  
  <pre><code>src/
    public/
      index.php (100kb)
    vendor/
    ...
  </code></pre>
  
  <p>Desired output: (The container file system merged with the mounted host system files which exists. Note the size of the index.php file.)</p>
  
  <pre><code>src/
    public/
      index.php (200kb)
    vendor/
    ...
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre><code>src/
    public/
      index.php (200kb)
  </code></pre>
  
  <p>Example docker-compose.yml</p>
  
  <pre><code>version: '3.2'
  
  services:
      php:
        image: php
        volumes:
          - ./src:/src
  </code></pre>
  
  <p>Edit: So it looks like overlayfs implemented by docker is only used for bulding docker images and can not be used for volumes what so ever. I still think it's possible to specify a custom driver but not sure how. As a temp fix I've done some fancy stuff with mapping stuff out of container, diffing it and putting it back in but not ideal.</p>