Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (2.3k points)

Hey guys, I am a bit new to Docker. So I messed up a little here and there and in short, I have a lot of images now, a lot of unwanted images. So is there a way i can remove all of these images without having to remove them manually? Like is there a proper flag or command for this?


1 Answer

+1 vote
by (6.9k points)
selected by
Best answer

Well it's all right, every makes mistake. 

Yes there is a way to do this. 

The below command will basically remove all the docker images that are there in your local directory.

$ docker rmi -f $(docker images -a -q)

If you only want to remove the unused images use this command :

$ docker image prune -a

A disclaimer : You cannot remove any image if there is a container running using it, so you'll have to remove the container first and then the image.

You can remove all the containers and the volumes attached to them using this command :

$ docker rm -vf $(docker ps -a -q) 


if you want to clear out everything in your docker system use this command :

$ docker system prune -a --volumes 

 Hope this helps :)

Also I understand docker can a be a bit tough, but it's fine, everything takes time. check out this Docker Training course if you are interested in getting trained by industry professionals.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories