WordPress & Volumes (Persistent Storage Question)

I’m confused about something. I’m new to using volumes and trying to understand something about an application that needs persistent file storage, like WordPress. I’m using this image: https://hub.docker.com/_/wordpress. The docker-compose.yml file uses a volume to store the MySQL data:

volumes:
- db_data:/var/lib/mysql

Which I think I understand how that part works, but what I don’t understand is where are the changes files stored? For example, if I install a WordPress plugin, yes, the MySQL data storage is persistent, but about the plugin files that are added to the file system? What am I missing here?

version: ‘3.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:
- “8080:80”
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data: {}

If you declare a named volume in a compose file, it will be bound to the docker-compose lifecycle. It will be created on docker-compose up and destroy with docker-compose down. If you want to uncouple the named volume, you need to create the volume outside the compose file (docker volume create …) and use it inside the compose file by declaring the volume as “external: true” .

You can use docker inspect db_data to see where it is stored. Though, since everything is prefixed with “foldername_” it might be docker inspect {foldername_}db_data instead.

Typicaly /var/lib/docker is the docker root dir, which leads to files beeing in /var/lib/docker/volumes/{volumename or a random id}/. You can check your root dir with docker info | grep "Root"

1 Like

I’ve never seen volumes being destroyed. This moment I’m developing on a system where one service is a postgres container with

services:
  db:
    image: postgres
    ...
    volumes:
      - db:/var/lib/postgresql/data

    ...

volumes:
  db:

and the databases on db are present every time I start it up.

1 Like

Our development partners complained until a couple of month ago that their persistance state would be missing after docker-compose down.

I am glad if this is not the standard behavior anymore :slight_smile:

1 Like