I have a project that uses mysql, so I've built a container for mysql with docker-compose and it worked. I also have a volume for persistent data and while container is running for the first time it will create a database. However, I droped that database. After running that container again, the database did not recreated. I've tried deleting my container, my image, executed prune process I've also tried
docker-compose down
docker-compose rm
docker-compose stop
docker-compose down --rmi all
I've deleted the volume folder and it didn't help either
This is my folder structer:
mysql/
scripts/
create_users_table.sql
data/
docker-compose.yaml
And this is my docker-compose.yaml file
version: '3.9'
services:
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: password
ports:
- 33060:3306
volumes:
- /mysql/data:/var/lib/mysql
- /mysql/scripts:/docker-entrypoint-initdb.d
The mysql
container will initialize the database on startup when the /var/lib/mysql
directory in the container is empty. So to reset the database you need to empty that volume.
Since in your docker-compose.yml
you have bind-mounted this directory you need to delete all contents in the /mysql/data
directory of the docker host.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.