Over time my local development machine gets messy with a lot of container images I've built, tested but never deleted. This can consume a lot of hard disk. With some containers still running it's not easy to see within 1 second what to delete and what not.
Luckily there's a nice Docker command to check your system and clean it up. With
docker system df you get a summary of your current usage:
❯ docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 48 9 25.8GB 25.35GB (98%) Containers 22 0 3.321GB 3.321GB (100%) Local Volumes 10 10 4.726GB 0B (0%) Build Cache 0 0 0B 0B
Delete dangling images
With a quick
docker image prune you can clean up your system. The command deletes all dangling images. Dangling images are images which are not in use by any container or are untagged.
docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
To bypass the Warning question you can pass
Delete all unused images
To remove all images that are not referenced by an existing container, not just the dangling ones, use the prune command with the
docker image prune -a
docker image prune command also allows you to remove images based on a condition using the
As of this writing the currently supported filters are
label. You can use more than one filter by using multiple
For example, if you want to remove all images that were created more than 24 hours ago, you can run the following command:
docker image prune -a --filter "until=24h"