Docker examples: Cleaning up unused Resources

Last updated:
Table of Contents

View docker files on Ubuntu

Docker files (images, containers, etc) are usually stored under /var/lib/docker on Ubuntu.

Delete all Images

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

Or, alternatively, using sudo:

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

Delete old Images

Unused images are called dangling images:

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

Delete all Containers

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

Delete stopped containers

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

Delete old volumes

Similarly, 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

Dialogue & Discussion