title: Mounting volumes with docker-compose
body: <p>I'm looking into how to mount volumes with docker-compose for data persistence but I'm having trouble understanding all the examples I read.</p>
  
  <p><a href="https://www.linux.com/learn/docker-volumes-and-networks-compose" rel="nofollow noreferrer">https://www.linux.com/learn/docker-volumes-and-networks-compose</a></p>
  
  <pre><code>version: '2'
  
  services:
  
   mysql:  
  
    image: mysql
  
    container_name: mysql
  
    volumes:
  
      - mysql:/var/lib/mysql
  
  ...
  
  volumes:
  
   mysql:
  </code></pre>
  
  <p>Ok so this defines a volume named mysql at the bottom and it references this volume in </p>
  
  <pre><code>- mysql:/var/lib/mysql
  </code></pre>
  
  <p>How will the mysql image know to look in this volume named mysql? Is it just designed to look in all the volumes it has to store data or something?</p>
  
  <p>Then in other examples I see the following:</p>
  
  <pre><code>services:
  
   nginx:
  
     image: nginx
  
     depends_on:
  
       - ghost
  
     volumes:
  
       - ./default.conf:/etc/nginx/conf.d/default.conf
  
     ports:
  
       - "80:80"    
  
     networks:
  
       - proxy
  </code></pre>
  
  <p>This example doesn't need to define a volume, why is that?</p>