I run mysql container using Docker. I start it with like
sudo docker -d --name mysql -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql mysql_image
I suspect that stopping mysql by stopping docker is not safe. Am I wrong?
sudo docker stop mysql
Is it safer to stop mysql inside of the container first?
sudo docker exec mysql /usr/bin/mysqladmin shutdown
looks safe, from the docs:
The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL.
so if the main process is mysqld, it will have a decent chance to flush everything.
Seems like stopping docker container without shutting down MySQL within creates broken MySQL data volume. So it is necessary to run MySQL shutdown before stopping container in order for MySQL to flush all changes to a disk.
This is a log of starting mysql on volume, created from container, stopped by docker. Pay attention to XA crash recovery step exists.
When using
before killing a container, XA crash recovery is not starting and data volume is valid for the next container start with it
you can check the logs from mysql container
to confirm whether the shutdown procedure is safe or not
to see the last line if shows:
[Note] mysqld: Shutdown complete
that should be safe
Go inside the guest host using your command terminal
Go inside the SQL_command_Line
Command shutdown the database inside there.