Reputation: 43
I have docker-compose.yml file for WordPress every time I run the docker-compose up the DB is empty and I need to run the 5 step install.
I don't understand what I need to do. I have a live Wordpress site, I clone into my local, create the yml file.
this is the yml file.
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: '${ROOT_PASSWORD}'
MYSQL_DATABASE: '${DB_NAME}'
MYSQL_USER: '${DB_USER}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: '${ROOT_PASSWORD}'
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: '${DB_HOST}'
WORDPRESS_DB_USER: '${DB_USER}'
WORDPRESS_DB_PASSWORD: '${DB_PASSWORD}'
WORDPRESS_DB_NAME: '${DB_NAME}'
volumes:
db_data:
driver: local
this is what I see before I run docker-compose up -d
local 2d6a924b957f092ea8e0f3e468ff3057021a23be6cab1cb9a468c47b1d0afc2c
local 5e098507d458788bc9393added71e8190e5919d6cfabfe90af4d26ab7aaf8ba1
local 58ee3acf025fd46403db6f0a51f0f872c4553204482e1481571da8391c3e3203
local 75bd69c4e1ebcc050035c8c8cf2b14371855ba79351bfbcdacc0181ada27ae35
local 0673aac3c62071a3e20969620cf6a44bb0c8a580fe572da376fdeafa34ec1e48
local 732ef89d1079c69696d2ac8097765dcc691706c682440a2aba0d0cf87f02039a
local 2183d9eca34bae8d12a1dd2ae0836d1261251041eec33a390f3b6c204f58bb74
local 94070855b40779105827b48a12384e08035e20fc8d2c6325b97fc4ff8f59149e
and this is what I see after
DRIVER VOLUME NAME
local 2c68ba0ccf1a44e63cea5b87160138912a279161ab62561a4e41c467aeb89018
local 2d6a924b957f092ea8e0f3e468ff3057021a23be6cab1cb9a468c47b1d0afc2c
local 5e098507d458788bc9393added71e8190e5919d6cfabfe90af4d26ab7aaf8ba1
local 58ee3acf025fd46403db6f0a51f0f872c4553204482e1481571da8391c3e3203
local 75bd69c4e1ebcc050035c8c8cf2b14371855ba79351bfbcdacc0181ada27ae35
local 0673aac3c62071a3e20969620cf6a44bb0c8a580fe572da376fdeafa34ec1e48
local 732ef89d1079c69696d2ac8097765dcc691706c682440a2aba0d0cf87f02039a
local 2183d9eca34bae8d12a1dd2ae0836d1261251041eec33a390f3b6c204f58bb74
local 94070855b40779105827b48a12384e08035e20fc8d2c6325b97fc4ff8f59149e
local bz_research_db_data
Upvotes: 1
Views: 1076
Reputation: 264761
The command docker-compose down --volume
has the following behavior from docker-compose down --help
:
Stops containers and removes containers, networks, volumes, and images
created by `up`.
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the `networks` section of the Compose file
- The default network, if one is used
Networks and volumes defined as `external` are never removed.
...
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.
So with the --volumes
arg, you are intentionally deleting the bz_research_db_data
volume, as you can see in your output.
The solution is to just run docker-compose down
instead, which will leave the named volumes behind for later reuse.
Upvotes: 1