We can use the Docker image rm, Docker rmi, and Docker image prune commands to remove or un-tag one or multiple Docker images from the host machine. Both the commands can be used to delete or remove Docker images. We can use this command with the tag as a parameter to remove images that have multiple tags. We can also combine the Docker rmi command with a sub-command to remove all Docker images at once.
However, the Docker image rm or rmi commands do not delete or remove images from the registry. Moreover, if an image has active containers associated with it, you cannot remove the image unless you use the -f
(force) option.
In this article, we will discuss how to remove docker images from a host machine through various commands. Before we move ahead, you should check out the following guides to udnerstand the topic in a better way.
Remove Docker Images
We can remove Docker images using three different ways. Let’s check out all of them one by one.
Docker Image rm Command
We can use this command to delete Docker images (one or more) from the host machine. The general syntax of the Docker image rm command is –
$ docker image rm [OPTIONS] IMAGE [IMAGE...]
The options that can be used along with this command is –
Name | Shorthand | Description |
--force | -f | To remove docker images forcefully. |
--no-prune | To avoid deleting untagged parent images. |
Let’s list all the Docker images first.

Let’s try to remove the fedora image with tag 23 using the Docker image rm command.
$ docker image rm fedora:23

We can list the images once again to verify the removal of the image.

We can see that the fedora:23 image has been removed.
Now, for the hello-world image, we have a container associated with it. To check this, we can list all the Docker containers.
$ docker container ls -a

If we try to remove this image, it will throw an error. Let’s check this out.
$ docker image rm hello-world

To avoid this, we can either stop the container and then remove this image, or use the force option along with the Docker image rm command. Let’s use the second one.
$ docker image rm -f hello-world
You can see that the image has now been deleted.

Delete Image Using Docker rmi Command
We can also use the Docker rmi command to delete Docker images. The syntax of this command is –
$ docker rmi [OPTIONS] IMAGE [IMAGE...]
Let’s try to delete the busybox image.
$ docker rmi busybox

We can use the -f (force) option here as well. Let’s try to forcefully delete the flaskapp image for which we have a container created.
$ docker container ls -a

Let’s try to remove the flaskapp image.

You can see that the image has been removed.
Delete Docker Images using Docker Image Prune Command
The Docker image prune command is used to remove all the dangling images. Dangling images are those that are just image layers and have no use now. The syntax of the Docker prune command is –
$ docker image prune [OPTIONS]
The options that we can use are –
Name | Shorthand | Description |
--all | -a | To remove or delete all unused images and not just the dangling ones. |
--filter | You can provide filter values such as ‘until=<timestamp>’. | |
--force | -f | You can remove images forcefully without any prompt for confirmation. |
Let’s first list all the Docker images.

Now, let’s prune the dangling and unused images using the –all option.
$ docker image prune --all

Now, let’s list all the images once again.

You can see that all the Docker images have been removed.
How to delete all Docker Images at once?
To delete all the Docker images at once, you can use the following command.
$ docker rmi -f $(docker images -a -q)
In the parent command, we have used the docker rmi command with the force removal option. In place of the image name, we have mentioned a sub-command which returns the list of image IDs of all the images quietly.
Let’s list all the Docker images first.

Now, let’s remove all of them using the above-mentioned command.

If we list all the Docker images again, we will find that there is no image available now.

Final Thoughts!
To sum up, in this article we discussed how to delete or remove Docker images from the host. We discussed 3 different method to do so – Docker image rm, Docker rmi, and Docker image prune commands. Finally, we also discussed how to remove all Docker images at once.
If you have any queries or suggestions, please mention them in the comments and we will have our experts get back to you. Also, check out complete and free Docker Tutorials.