title: How do named volumes work in docker?
body: <p>I'm struggling to understand how exactly does the named volume work in the following example from docker <a href="https://docs.docker.com/compose/compose-file/#volume-configuration-reference" rel="noreferrer">docs</a>:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>version: "3"
  
  services:
    db:
      image: db
      volumes:
        #1
        - data-volume:/var/lib/db
    backup:
      image: backup-service
      volumes:
        #2
        - data-volume:/var/lib/backup/data
  
  volumes:
    data-volume:
  </code></pre>
  
  <p>My guess is, that the first occurrence of the named volume <em>(#1)</em> <strong>defines</strong> what is contained inside the volume, while subsequent occurrences <em>(#2)</em> simply <strong>share</strong> the volume's content with whatever containers they are referenced from. </p>
  
  <p>Is this guess correct?</p>