Docker for macで起動したmysqlコンテナでInnoDBのエラーが出る/「No space left on device」みたいなエラーが発生する場合の対処法

ヨメレバCSS
オリジナルCSS

 Docker for macで開発をしているときに、急にmysqlのコンテナが起動しなくなってしまったことがありました。

 環境はDokcer for mac 18.06.0-ceです。

スポンサーリンク
GoogleAdSence レクタングル(大)

Volumeの使いすぎでホストOSの容量が不足したっぽい

 docker-compose upしようとすると次のようなエラーが出て止まってしまいます。

[ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 0 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!
[ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!

 コンテナを消してやり直したりしていると、「no space left on device」といったエラーも混ざってきていました。

 Dockerコンテナに入ってみると、ルートディレクトリが100%でした。

$ docker-compose exec mysql bash
root@xxxxxxxx:/# df
Filesystem     1K-blocks      Used Available Use% Mounted on
overlay         61255492  57681200    432968 100% /
tmpfs              65536         0     65536   0% /dev
tmpfs            3050260         0   3050260   0% /sys/fs/cgroup
osxfs          488245288 247032424 239477272  51% /db
/dev/sda1       61255492  57681200    432968 100% /etc/hosts
shm                65536         0     65536   0% /dev/shm
tmpfs            3050260         0   3050260   0% /proc/acpi
tmpfs            3050260         0   3050260   0% /sys/firmware

 どうも、Dockerコンテナが乗っているほうがいっぱいになってしまったみたい。

Volumeを掃除して解決する

 これは不要なコンテナを削除してみても、解決できませんでした。

 Dockerのディスク使用状況がdocker system dfで確認できるようなので行ってみます。

$ docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              23                  16                  4.759GB             3.614GB (75%)
Containers          324                 0                   486MB               486MB (100%)
Local Volumes       252                 21                  52.76GB             50.96GB (96%)
Build Cache         0                   0                   0B                  0B

 Volumesがだいぶ占めていますがコンテナも不要です。なので両方消してみました。

$ docker container prune
$ docker volume prune
$ docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              23                  12                  4.759GB             3.625GB (76%)
Containers          27                  6                   963.9kB             854kB (88%)
Local Volumes       7                   7                   175.9MB             0B (0%)
Build Cache         0                   0                   0B                  0B

 docker container pruneで使用していないコンテナを削除、docker volume pruneでコンテナに紐付いていないVolumeを削除しました。

 しかし、この状態からdocker-compose upしてみると、まだmysqlがこけます。

[ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 0 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!
[ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!

 どうもcontainer pruneで消えてくれなかったようなので、docker-compose rmでコンテナを消してやります。

 その後、docker-compose upで起動すると、うまく動いてくれました。

参考:

 本記事はDocker ver20.10.8の環境で確認しています。 このコマンドは、参照されていないデータボリュームの一括削除ができます。 参照されていないというのは、コンテナから利用されていないデータボリュームのことでして、無駄な領域の

スポンサーリンク
GoogleAdSence レクタングル(大)

シェアする

スポンサーリンク
GoogleAdSence レクタングル(大)