Mysql – safe way to stop thesql docker container

dockerMySQL

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

Best Answer

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.