Persist data in WordPress MySQL

I am new to docker and trying to understand how docker in general would save the data in MySQL. We are in process of migrating content so this is going to be a fresh install of WP, then developers would work on migrating data from old CMS to WP. We would like to save this data and then it is deployed in production we would like to make sure that the local copy of MySQL along with changes to WordPress are carried over to production.

Right now I can start a new container, store some data but as soon as I do docker-compose down I am going to lose any data I have in MySQL database. How do I go about dealing with this? I am attaching compose file in this question for reference.

I am using Windows 10 for local dev work and the compose file I am using is something I found online so I am trying to understand every aspect of docker as I read more documentation so please treat me as a newbie and would appreciate if someone could help me with this.

version: “3”

services:
wordpress:
image: “wordpress:${WP_VERSION:-4.9.7}-php${PHP_VERSION:-7.2}-apache”
environment:
VIRTUAL_HOST: “${DOCKER_DEV_DOMAIN:-project.test}”
WORDPRESS_DB_HOST: “mysql”
WORDPRESS_DB_NAME: “wordpress”
WORDPRESS_DB_PASSWORD: “”
WORDPRESS_DB_USER: “root”
depends_on:
- “mysql”
networks:
- “front”
- “back”
volumes:
- “wp:/var/www/html:rw”
#- “./certs/ca-root/ca.crt:/tmp/certs/root.crt:ro”
- “./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro”
- “./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro”
- “./src/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins”
- “./src/vip-go-skeleton/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins”
- “./src/vip-go-skeleton/images:/var/www/html/wp-content/images”
- “./src/vip-go-skeleton/languages:/var/www/html/wp-content/languages”
- “./src/vip-go-skeleton/plugins:/var/www/html/wp-content/plugins”
- “./src/vip-go-skeleton/private:/var/www/html/wp-content/private”
- “./src/vip-go-skeleton/themes:/var/www/html/wp-content/themes”
- “./src/vip-go-skeleton/vip-config:/var/www/html/wp-content/vip-config”
ports:
- “8082:80”
- “443:443”
wp-cli:
image: “wordpress:cli-php${PHP_VERSION:-7.2}”
environment:
- APACHE_RUN_USER=“www-data”
- APACHE_RUN_GROUP=“www-data”
depends_on:
- “mysql”
networks:
- “back”
volumes:
- “wp:/var/www/html:rw”
- “./bin/install-wp.sh:/usr/local/bin/install-wp:ro”
- “./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro”
- “./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro”
- “./src/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins”
- “./src/vip-go-skeleton/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins”
- “./src/vip-go-skeleton/images:/var/www/html/wp-content/images”
- “./src/vip-go-skeleton/languages:/var/www/html/wp-content/languages”
- “./src/vip-go-skeleton/plugins:/var/www/html/wp-content/plugins”
- “./src/vip-go-skeleton/private:/var/www/html/wp-content/private”
- “./src/vip-go-skeleton/themes:/var/www/html/wp-content/themes”
- “./src/vip-go-skeleton/vip-config:/var/www/html/wp-content/vip-config”
photon:
image: “chriszarate/photon:latest”
networks:
- “front”
mysql:
image: “mariadb:10.2”
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: “yes”
MYSQL_DATABASE: “wordpress”
MYSQL_ROOT_PASSWORD: “”

networks:
  - "back"
ports:
  - "3306:3306"

proxy:
image: “jwilder/nginx-proxy:alpine”
environment:
HSTS: “off”

networks:
front: {}
back: {}

volumes:
wp: {}

Hi

A good place to start, is always the hub.docker page for the image you use, in this case, mariadb: Docker, there is a section “Where to Store Data” :slight_smile:

tl;dr:

put this under the mysql section:

volumes:
  - “/my/own/datadir:/var/lib/mysql”

hi,

I tried that and noticed that site wouldnt start up. So I started debug (docker events) and see a container die there. So I am not sure how to debug it.

I would suggest take a look at:

You could always check docker logs for the mysql container, if thats the container that dies

I added this following line to the compose file and now I am getting this error. If I remove that line it works fine.s

volumes:
- ${DB_PATH}:/var/lib/mysql

and in the env file this is what path to store database looks like
DB_PATH=c:/temp/data

Am I missing something?

Which env file?
because the ${DB_PATH} is read from the host, and not in the container.

There is .env file that I have in the root where docker-compose.yml resides. ${DB_PATH} points to the host and nothing inside the container.