Docker examples: Cleaning up unused Resources

Docker examples: Cleaning up unused Resources

Last updated:
Table of Contents

Docker file location

Docker files (images, containers, etc) are stored

  • under /var/lib/docker on Ubuntu

Delete all images

$ docker rmi -f $(docker images --quiet)

List unused images

$ docker images --filter "dangling=true"

Delete ununsed images

Unused images are called dangling images:

$ docker rmi $(docker images --quiet --filter "dangling=true")

Delete image

List images with docker images to list images.

Then use docker rmi <image-id> remove an image.

List stopped containers

$ docker ps --filter status=exited

Delete all Containers

$ docker rm $(docker ps --all --quiet)

Delete stopped containers

$ docker rm $(docker ps --quiet --filter status=exited)

Delete old volumes

Unused volumes are called dangling volumes.

Use docker volume prune

Example:

$ 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:
d86058fca26da835071a6239f413246135891f1efe894c381c77814273ed465d
f665d5b878c81b532e839a62b3ed065f3ea0413983b5617deb88f9013031f810
17b1418992e34954d005f1661f12ea146313eea0fca0627e5aadd724e30cd918
1d388af5b0a60c74ad62808adf9d062abddffc6db1068672a5d7897f25510412
446f6cc3e9be4a41659a152391519b2140b0938f27aea6343efc41df55cd7527
81ee12ca8921917bf042279c53e5100a734a665ca481d77db67491f5266d577c
aac2c2e47a81906c2f632ec526414c1c5162876b882fa7546722564f0694d256

Total reclaimed space: 4.75GB