title: How to cache package manager downloads for docker builds?
body: <p>If I run <code>composer install</code> from my host, I hit my local composer cache:</p>
  
  <pre><code>  - Installing deft/iso3166-utility (1.0.0)
      Loading from cache
  </code></pre>
  
  <p>Yet when building a container having in its Dockerfile:</p>
  
  <pre><code>RUN composer install -n -o --no-dev
  </code></pre>
  
  <p>I download all the things, e.g.:</p>
  
  <pre><code>  - Installing deft/iso3166-utility (1.0.0)
      Downloading: 100%         
  </code></pre>
  
  <p>It's expected, yet I like to avoid it. As even on a rebuilt, it would also download everything again.</p>
  
  <p>I would like to have a universal cache for composer that I could also reshare for other docker projects.</p>
  
  <p>I looked into this and found the approach to <a href="https://git.framasoft.org/Chill-project/docker-ci-image/commit/002aeaf8ae5845c71eb8191821a98aa7a8565f0e" rel="noreferrer">define a volume in the Dockerfile</a>:</p>
  
  <pre><code>ENV COMPOSER_HOME=/var/composer
  VOLUME /var/composer
  </code></pre>
  
  <p>I added that to my <code>Dockerfile</code>, and expected to only download the files once, and hit the cache afterwards.</p>
  
  <p>Yet when I modify my <code>composer</code>, e.g. remove the <code>-o</code> flag, and rerun <code>docker build .</code>, I expected to hit the cache on build, yet I still download the vendors again.</p>
  
  <p>How are volumes supposed to work to have a data cache inside a docker container?</p>