Doubt as to the marking "volumes" inside docker-compose.yml

2

The docker-compose.yml below was taken from the docker documentation itself. My question is: why in the db container do we have the volume reference and at the end of the file the same reference is repeated? What does it mean?

version: '3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress

volumes:
    db_data:
    
asked by anonymous 08.10.2017 / 04:43

1 answer

0

Although it is common to leave this information in the end, the order really is indifferent. The main elements (which are at the root of yaml) Networks and Volumes are used to specify resources, respectively networks and volumes.

This form of structure reaffirms the assurance that you will only use volumes or networks that you have previously defined. The definition of these is global for your yaml.

  

Only after specified can these be used in   services / containers. This model is then given beyond the name (as we see   in the case of volume) we can define driver and other information, in   counterpart we can re-use the same volume in several   containers.

    
09.10.2017 / 10:48