はじめに
この記事では、Dockerのビルドキャッシュを削除する方法を記載します。
Dockerのディスク使用量を確認する
Dockerのビルドキャッシュを削除する前に、docker system dfを実行して、Dockerのディスク使用量を確認しておきます。
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 7 6 4.019GB 1.423GB (35%)
Containers 11 0 14.58MB 14.58MB (100%)
Local Volumes 0 0 0B 0B
Build Cache 81 0 2.517GB 2.517GB
Dockerのビルドキャッシュを削除する
Dockerのビルドキャッシュを削除するには、docker builderのpruneを使います。
$ docker builder prune --help
Usage: docker builder prune
Remove build cache
Options:
-a, --all Remove all unused build cache, not just dangling ones
--filter filter Provide filter values (e.g. 'until=24h')
-f, --force Do not prompt for confirmation
--keep-storage bytes Amount of disk space to keep for cache
docker builder pruneを実行します。
$ 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:
...
ビルドキャッシュが削除されたことを確認する
ビルドキャッシュを削除したあとに、docker system dfを実行し、ビルドキャッシュが削除されていることを確認します。
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 6 5 3.254GB 901.1MB (27%)
Containers 11 0 14.58MB 14.58MB (100%)
Local Volumes 0 0 0B 0B
Build Cache 53 0 0B 0B