9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

用済みのDockerボリュームを選択して削除する方法

Last updated at Posted at 2025-04-16

定期的に新規作成するコンテナの削除後、用済みになったボリュームが残ったままになって蓄積され容量を圧迫していたため、docker volume prune -aで使われていないボリュームを全て消すのではなく、このコンテナに関係するボリュームだけをまとめて削除する方法を調べた結果のメモです。

用済みボリュームを選択して削除する

今回の本題、用済みボリュームのうち対象となるものを選択してまとめて削除する方法です。
以下のように--filterオプションを利用します。-aオプションを付けないと匿名コンテナしか削除できません。

docker volume prune -a --filter "label=foo=bar"

docker volume pruneでサポートされているフィルターはlabelフィルターのみで、上記のようにlabel=<key>=<value>label=<key>label!=<key>=<value>といった形で使うことができます。ラベル以外には対応していないため、この方法を使う場合には、あらかじめ対象のボリュームに他のボリュームと区別可能なラベルを付与しておく必要があります。

おまけ

その他用済みオブジェクトの削除方法

イメージ

docker image prune

コンテナ

docker container prune

ネットワーク

docker network prune

ボリューム以外全て

docker system prune

ボリューム含めて全て

docker system prune --volumes

参考

docker system prune
docker volume prune

9
3
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
9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?