Introduction

Dangling images are images that are not referenced by other images. If you have a lot of them, removing them can be a tedious task. This is a tip on how to quickly remove them.

Listing all images with dangling

You can list images using:

$ docker image ls
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
<none>                     <none>              a6a1c542e753        12 days ago          300MB
<none>                     <none>              a1c542e753er        12 days ago          300MB
<none>                     <none>              828604fef5s1        12 days ago          300MB
<none>                     <none>              9ab828604fef        12 days ago          300MB

This shows a list of dangling images. The REPOSITORY and TAG fields are <none>.

Deleting dangling images

Using docker rmi and filters

You can list and filter out the dangling images, then remove them like this:

$ docker rmi -f $(docker images -f "dangling=true" -q)

Using docker prune

Newer versions of docker (1.13+) have a pruning command you can run to remove dangling images:

$ docker system prune

Conclusion

You can run these commands regularly to clear dangling images and save space. You can create a cron job to run or manually do it yourself.