Dockerのoverlay2でMySQLが起動しない問題を解決する


公式のMySQLコンテナは、Storage Driverがoverlay、overlay2だとMySQLが起動しないことがあります。

Docker for Mac(Windows)は、デフォルトのStorage Driverがoverlay2なので、この問題を回避するために、Storage Driverをaufsに変更していました。

※ちなみに、CoreOSではdevicemapperに変更していました。
https://qiita.com/yKanazawa/items/1827325c92fd4651a912

しかし、先日リリースされた、Docker for Windows 2.0.0.0-Mac78(Win78)では、aufsへの切り替えができなくなっていました。

なので、この問題に本格的に向き合うことになったのですが、以下のGitHub issueが大変参考になりました。

MySQL does not start with overlay2 and overlay but starts with aufs
https://github.com/docker/for-linux/issues/72

Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option
https://serverfault.com/questions/870568/fatal-error-cant-open-and-lock-privilege-tables-table-storage-engine-for-use

MySQLの起動前に以下のコマンドを実行することで、MySQLが起動できるようになります。

find /var/lib/mysql -type f -exec touch {} \;