I'm trying to get my head around docker and confused how the volumes work.
On the official documentation there's a bit of code similar to the docker-compose.yml
file I'm working with.
version: "3.7"
services:
wordpress:
image: wordpress
ports:
- "8080:80"
networks:
- overlay
deploy:
mode: replicated
replicas: 2
endpoint_mode: vip
mysql:
image: mysql
volumes:
- db-data:/var/lib/mysql/data
networks:
- overlay
deploy:
mode: replicated
replicas: 2
endpoint_mode: dnsrr
volumes:
db-data:
networks:
overlay:
I'm confused as to what the db-data:/var/lib/mysql/data
refers to and where docker is actually storing the database data, especially as /var/lib/mysql
doesn't exist as a directory on the host.
So this line
volumes:
- db-data:/var/lib/mysql/data
basically mounts the volume db-data
from host into /var/lib/mysql/data
in the container.
If db-data
doesn't exist Docker will create one for you in Host.
You can read more here.