Clean stopped containers & dangling images #docker

May 29, 2019|
1 min read
  • devops

Originally posted by me on Hashrocket TIL

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.


© 2023, Dorian Karter