Bobcares

Docker prune untagged images

by | Dec 29, 2022

Wondering how to resolve Docker prune untagged images? you are in luck! Our experts have put together this guide to help you get started. Our Docker Support team is here to lend a hand with your queries and issues.

Docker prune untagged images

Sometimes when testing and developing, some images become dangling, which means untagged images.

They can always be safely removed to free disk space.

Running docker images -f dangling=true will list them:

And you can clear them with docker rmi $(docker images -f dangling=true -q).

This command will only eliminate dangling images used in containers, even if not currently running.

Remove all stopped containers

docker rm $(docker ps -a -q)

This will remove all stopped containers by getting a list of all containers with docker ps -a -q and passing their ids to docker rm.

This should not remove any running containers, and it will tell you it can’t remove a running image.

Remove all untagged images

In the process of running docker I had accumulated several images that are not tagged.

To remove these we use this command:

docker rmi $(docker images | grep “^<none>” | awk “{print $3}”)

This works by using rmi with a list of image ids. To get the image ids we call docker images then pipe it to grep “^<none>”.

The grep will filter it down to only lines with the value “<none>” in the repository column.

Then to extract the id out of the third column we pipe it to awk “{print $3}” which will print the third column of each line passed to it.

After running these two commands I recovered 15G of space.

There may be more I could do to recover more space, my docker graph directory still is over 5G, but for now this works.

Conclusion

To conclude, our Support Engineers demonstrated how to deploy resolve Docker prune untagged images.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.