LoginSignup
6
5

More than 1 year has passed since last update.

Docker がシステムの容量を圧迫している時

Posted at

Docker がシステム全体のストレージ容量を圧迫していたり、 Docker に与えたディスク容量が使い切られることがある。

Mac でこれを解決した際の備忘録。

現在の使用量を確認する

イメージ、コンテナ、ボリューム、ビルドキャッシュそれぞれの使用量が表示される。 1

$ docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          62        0         40.1GB    40.1GB (100%)
Containers      0         0         0B        0B
Local Volumes   6         0         1.217GB   1.217GB (100%)
Build Cache     462       0         6.574GB   6.574GB

いらないデータを削除する

各サブコマンドに prune というコマンドが用意されている。不要な (dangling) データを削除してくれる。

イメージ

$ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:(sha256ハッシュ)
# ...

Total reclaimed space: 0B

コンテナ

$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
(コンテナ ID)
# ...

Total reclaimed space: 968.8kB

ボリューム

$ docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
(ボリューム ID)
# ...

Total reclaimed space: 250B

ビルドキャッシュ

$ docker builder prune
WARNING! This will remove all dangling build cache. Are you sure you want to continue? [y/N] y
Deleted build cache objects:
(キャッシュ ID)
# ...

Total reclaimed space: 7.58GB

全部まとめて

$ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y

Total reclaimed space: 0B

それでも解決しない時

prune コマンドに -f-a のオプションをつけるとさらに頑張ってくれる。しかし、これらは dangling でなく単に使われていないリソースも強制的に削除するため、注意して使う。

筆者の場合は system prune -af を実行して 20.16GB が解放された。

  1. 筆者はすでに container と image を少し整理したあと実行した

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5