未使用な Docker image, container, volume, network, cache などの一括削除方法

未使用な Docker image, container, volume, network, build cache などを一括削除する方法をご紹介します。

Docker

未使用な containers, networks, volumes, images, build cache を一括削除

docker system prune --volumes

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N]

docker system prune | Docker Documentation

未使用な docker container

未使用な docker container 一覧

docker ps -a -f status=exited

未使用な docker container 一括削除

docker rm $(docker ps -a -f status=exited -q)

未使用な docker volume

未使用な docker volume 一覧

docker volume ls -f dangling=true

未使用な docker volume 削除

docker volume prune

docker volume prune | Docker Documentation

未使用な docker image

未使用な docker image 一覧

docker images -f dangling=true

未使用な docker image 一括削除

docker images purge

docker image prune | Docker Documentation

未使用な docker network

未使用な docker network 一括削除

docker network purge

docker network prune | Docker Documentation

以上、未使用な Docker image, container, volume, network, build cache などを一括削除して disk 容量を空けておきたい、現場からお送りしました。

参考情報