LoginSignup
228
197

More than 5 years have passed since last update.

未使用のコンテナ、volumeなどを一括削除

Last updated at Posted at 2018-03-08

概要

dockerを運用していると不要なコンテナやvolumeなどが溜まっている場合があるので、一括削除するためのメモを残す。

停止コンテナ一括削除

status=exitedで停止コンテナの一覧を取得して、一括削除する。
docker container prune | Docker Documentation

ターミナル
$ docker rm `docker ps -f "status=exited" -q`

or

$ docker container prune

未使用のVolumeを一括削除

dangling=trueでコンテナから参照されていないVolumeの一覧を取得して、一括削除する。
docker volume prune | Docker Documentation

ターミナル
$ docker volume rm $(docker volume ls -qf dangling=true)

or

$ docker volume prune

未使用のイメージを一括削除

docker image prune | Docker Documentation

ターミナル
$ docker image prune

$ docker image prune -a

未使用のネットワークを一括削除

docker network prune | Docker Documentation

ターミナル
$ docker network prune

未使用なコンテナ, イメージ, ネットワークを一括削除

docker system prune | Docker Documentation

ターミナル
$ docker system prune

# volumeも破棄する場合はこちら
$ docker system prune --volumes

参考サイト

228
197
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
228
197