There might be several Docker images on your host machine that serve no purpose at all. Keeping such unused, un-tagged, or dangling images simply eats up lots of space unnecessarily. Hence, it’s a wise decision to remove the images. In the article How to Remove Docker Images?, we have discussed how to remove selected Docker images from your system. In this article, we will discuss how to remove all Docker images together from the host.
There are several methods to remove all Docker images from the system. However, in order to delete images, you need to ensure that these images don’t have any container associated with them. In such cases, you should first remove all the associated containers and then delete all the images. But there is another workaround to this. You can use the –force option to delete images forcefully. We will look at all the possible methods to delete/remove all Docker images at once.
Before we move ahead, check out these articles to understand the topic better.
Remove all Docker Images
As discussed earlier, it’s always a better practice to remove all the associated containers first before removing all the Docker images. Let’s list all the images first.
$ docker images

Now, let’s list all the containers using the command below.
$ docker container ls -a

The above command lists all the existing Docker containers.
There are two ways to remove these containers. We can either use the docker container rm command to delete all the containers one by one before we delete Docker images. Or we can use the below command to delete all Docker containers simultaneously.
$ docker rm -f $(docker ps -a -q)

In the above command, we have used the force option to remove Docker containers that are both running and stopped. And instead of providing each container name one by one, we have used a subcommand that lists the container IDs of all the existing Docker containers.
Let’s list all the containers once again.
$ docker container ls -a

You can see that all the containers have been removed. Now, let’s use the following command to delete all Docker images together.
$ docker rmi -f $(docker images -q)

Here, we have tried to use the docker rmi command to remove all images forcefully using the force option. As a subcommand, we have used the docker images command which lists all the existing Docker images along with the quiet option. This only prints the Image IDs.
Let’s try to list all the images once again.

You can see that all Docker images are now removed.
Prune System to Delete all Docker Images
To delete Docker images all at once, we can also use the system prune command. However, the system prune command not only just deletes all the images, but also deletes all stopped containers, unused networks, unused volumes, and build cache.
The syntax to prune the sytem to delete all Docker images is –
$ docker system prune -a
Let’s list all the images first.
$ docker images

Now, let’s try to prune the system.

You can see that all the existing images have been deleted.
Docker Image Prune
Yet another method to delete all Docker images is to use the Docker image prune command. We can use options such as –all and –force to forcefully delete all the unused and dangling images. The syntax of the Docker image prune command is –
$ docker image prune --all --force
Let’s list all the images first.

Now, let’s use the Docker image prune command.

Final Thoughts!
To conclude, in this article, we discussed how to remove all Docker images at once. We discussed several methods such as using a subcommand with Docker rmi, Docker system prune, and Docker image prune commands to delete all Docker images from the system.
If you have any queries or suggestions, please mention them in the comment box. We will have our experts get back to you as soon as possible. Also, check out our free Docker Tutorials.