4
The Docker-Compose.yml below has been taken from the Docker documentation itself. My question is: why inside the db container we have the reference of volumes 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:
So this volume marking in the global scope is a definition, that is, a marking that the volume will be used. Right? This global marking is optional?
– Fábio Jânio
It’s not just an appointment, it’s the definition. Which may even be an external volume (which is not being created in your Compose, but was previously created).
– Luiz Carlos Faria
And it’s not optional
– Luiz Carlos Faria