Removing Unused or Untagged Docker Images
1 minute read
Avast, Ye Old Images!
If you’ve been trying out Docker or maybe just reading about it, you probably know that one of it’s strengths is the way in which builds progress by layer.
RUN commands all get executed in their own intermediate container. This is great for lots of reasons, but if you don’t use the
--rm=true flag when you run
docker build, you’ll get stuck with lots of these guys after a while:
##Make it so
Newer versions of Docker have made it a bit easier to do this than it was previously. Just pipe the list of filtered images you find with
docker images -q --filter "dangling=true to the
docker rmi command and voilà, you can free up (likely GBs of) space. Time to make like Mary Poppins.
docker rmi $(docker images -q --filter "dangling=true")
Ps: building with the
--rm=true will help prevent Docker image cluttering.