title: Docker Compose - Share named volume between multiple containers
body: <p>I'm using docker-compose and v3. I'm trying to mount a volume in docker:</p>
  <p><code>./appdata:/appdata</code></p>
  <p>I'd like to have this as a volume and then reference that volume from multiple containers. The <a href="https://docs.docker.com/compose/compose-file/#volume-configuration-reference" rel="noreferrer">volume configuration reference</a> only shows <code>data-volume:</code> as a named volume, with no value, so it doesn't look like the above.</p>
  <pre class="lang-yaml prettyprint-override"><code>services:
  
      nginx:
          build: ./nginx/
          ports:
              - 80:80
          links:
              - php
          volumes:
              - app-volume
  
      php:
          build: ./php/
          expose:
              - 9000
          volumes:
              - app-volume
  
  volumes:
       app-volume: ./appdata:/appdata
  </code></pre>
  <p>This gives me:</p>
  <blockquote>
  <p>ERROR: In file './docker-compose.yml', volume 'app-volume' must be a mapping not a string.</p>
  </blockquote>
  <p>Obviously I know I need to change the <code>volumes</code> key/value pair, but I'm not sure <em>how</em> to change this so I can share a volume between services.</p>
  <p>I've also checked out <code>volumes_from</code> but this effectively just allows inheritance from other containers. I've seen someone use <code>volumes_from</code> on another container that contains the mapping they want, but with <code>command: true</code> set so that the container is never actually run, which to me just seems like a hack.</p>
  <p>How can I do this?</p>
  <hr />
  <p>Note, I <em>do</em> have the following working:</p>
  <pre class="lang-yaml prettyprint-override"><code>nginx:
      volumes:
          - ./appdata:/appdata
  php:
      volumes:
          - ./appdata:/appdata
  </code></pre>
  <p>But that's just duplication and is something I'm hoping a named volume could help me avoid :-)</p>