How to persist MySQL container on Windows 10 between reboots

Cheers!

I’m using a native Docker for Windows Community Edition Version 17.03.1-ce-win12 (12058) on Windows 10 Pro x64 for WordPress development. I have two containers: WordPress and MySQL. MySQL container has a data volume where DB data is stored between runs. It is configured as:
volumes:
- ./database:/var/lib/mysql

I start containers with ‘docker-compose up -d’ and stop еруь with ‘docker-compose down’. When stopped this way, MySQL data is saved properly to the data volume and when I start it next time I see all my changes persisted.

However, if I reboot Windows 10 without stopping MySQL containers first, it seems that changes made to the database since the last start are not saved. Docker for Windows is smart enough to start the same volumes that were running before reboot but does it really not care about shutting them down properly so the DB data be saved? Is it really so or do I misunderstand anything?

What is the most reliable way to avoid losing data on a system reboot? Stopping all MySQL container manually before reboot is a tedious task, especially when multiple servers are running. Probably I can create a script that will parse ‘docker ps’ output and will stop all the MySQL containers before reboot but I’m afraid I am probably reinventing a wheel here.

What’s the best way to deal with a situation? I’ve searched high and low but found nothing on a topic. Am I the only one who is having this issue? Am I missing anything here? Should the container’s data be saved automatically to the volume by Docker on Windows reboot or not?

Any help really appreciated! Thanks!

I did some additional investigation and I think the problem I asked about never existed. It was actually a Docker for Windows issue of a different kind: https://github.com/docker/for-win/issues/584.

Here is what was happening.

  1. When machine was rebooted, all persistent MySQL data was in fact saved correctly.
  2. But after computer restart Docker was not able to mount a volume because the volume became available a few seconds after container was autostarted (please see a comment here: https://github.com/docker/for-win/issues/584#issuecomment-286792858). As a result of this, MySQL database was empty (volume was not mounted, no data can be read).

If to restart a container manually, all persistent data will become loaded properly. So it was not the issue I thought of, but a different issue that is, luckily, a much less severe one.