Today I Learned

hashrocket A Hashrocket project

Clean stopped containers & dangling images #docker

Today I learned how to clean stopped containers in Docker. Starting in Docker 1.13 a new prune command has been introduced.

docker container prune

(docs)

No one likes dangling images...

To list the numeric ids of dangling images dangling images use the filter with the dangling flag and -q to surpress anything but IDs:

dangling_images=$(docker images -qf dangling=true)

(docs)

Then delete the images

docker rmi $dangling_images

(docs)

You can add those to a script and run it from time to time to reclaim hard drive space and some sanity.

See More #devops TILs