You are currently viewing How to Delete Docker Image?

How to Delete Docker Image?

Docker simplifies the process of wrapping your apps and services into containers, allowing you to operate them in any environment. However, as you continue to work with Docker, it is simple to build up an excessive number of unnecessary images, containers, and data volumes. These clutter the output and occupy space on your drive.

Docker provides you with the ability to clean up your system directly from the command line using all of the tools that you need. This cheat sheet-style guide gives a quick reference to commands that are beneficial for clearing up disk space. It also helps in keeping your system organized by eliminating unwanted Docker images, containers, and volumes. We are also going to discuss why we should delete docker image. Follow the instructions described below to delete Docker image.

Why Delete Docker Image?

Images are saved and containers are run by the Docker Engine. The Docker Engine does this by reserving a fixed amount of disk space as a “storage pool” that may be used for storing images, containers, and anything else that Docker might need (such as global Docker volumes or networks).

The Docker Engine will stop functioning once that storage pool has reached capacity. We can’t make or get new images, and our containers won’t run.

Docker files take up most of the storage pool for Docker Engine, so we get rid of them to keep Docker going.

In addition, we delete images so that our Docker Engine stays clean and clutter-free. As an example, it’s easy to make a lot of pictures that we don’t need during development. Alternatively, we can download specific software images for testing purposes that we would later delete.

Docker images that have been downloaded from a Docker repository may be deleted without much difficulty. If there is a chance that we could require it in the future, we will just retrieve it from the repository once more.

But we need to be careful with Docker Images that we made ourselves. Once they have been deleted, our own images will no longer exist unless we have saved them. Docker images may be preserved in one of two ways: either by exporting them to a TAR file or by pushing them to a repository.

Also Check: Our blog post on how to install docker on mac

How to delete Docker Images?

There are several ways for people to remove Docker files, including:

Method 1: How to Use the “docker rmi” Command to delete a Docker Image?

The “docker rmi” command is considered to be one of the most effective Docker commands. Docker images may be deleted or untagged with its help. This command will only remove tags from the image container if it has more than one tag already. On the other hand, if the image just contains a single tag, then the “docker rmi” command will delete both the tag and the Docker image.

List Docker Image

When deleting Docker images, either the image ID or the image name is used. Use the “docker images” command to get a list of all Docker images; this will allow you to check either the image ID or the image name:

- docker images
List Docker Image

Delete Docker Image by ID

Use the command “docker rmi <image-id>” to delete the Docker image by its ID:

- docker rmi a5b5dddb2c8b
Remove Docker Image by ID

Delete Docker Image by Name

Using the following command, users can also delete the Docker image by specifying the image name:

- docker rmi golang:alpine
Remove Docker Image by Name

Delete Docker Image Associated With Any Container

If the Docker image is linked to any Docker containers, it might be hard for users to delete the Docker image with the easy “docker rmi” command. They may get an error stating that the container is utilizing an image reference, as seen in the following example:

Remove Docker Image Associated With Any Container

To delete a Docker image that is connected with any Docker container, use the “docker rmi” command and include the “-f” option in the command line arguments. The “-f” option will delete the Docker image in a forceful way:

- docker rmi -f pythonimage

It is possible to see that this image has been deleted:

docker rmi -f pythonimage

Delete multiple images

When you want to delete any specific images at once, there is a means to remove multiple images at a time. So, to do that, initially list the pictures to get their Image IDs, and then run the easy command that follows.

- docker rmi <your-image-id> <your-image-id> …

Enter the Image IDs into the command, followed by the spaces that should be in between each one.

Delete all images at once

There is an easy command that can be used to delete all of the images. docker rmi $(docker images -q).

There are two instructions included inside the preceding one. The first of these commands executes in the $() shell syntax and provides the results of whichever other commands are executed within that syntax. Therefore, in this -q- is an option that is used to offer return the unique IDs, $() provides the outcomes of image IDs, and then docker rmi eliminates all of those images.

Also Read: Our blog post on how to start docker daemon

Method 2: Using “docker image prune” Command to Remove Docker Image Using

Docker images can be removed and cleaned up with the use of the “image prune” command. This command will only remove photos that are “dangling,” meaning they are not related to any container or tag.

Use the following command if you want to delete docker images that are dangling:

docker image prune
- docker image prune

Make use of the “docker image prune” command together with the “-a” and “-f” options in order to delete unnecessary, stopped or dangling images:

- docker image prune -a -f
docker image prune -a -f

To be sure, make a new list of all the Docker images:

- docker images

It can be seen that all dangling and stopped images have been effectively deleted.


Users have the option of utilizing either the “docker image prune” or “docker rmi” command in order to delete Docker images from their systems. Docker’s “rmi” command may be used to delete images in addition to removing tags. Utilize the “docker rmi image-name>” command in order to delete the Docker image from your computer by utilizing the “rmi” command. Use the “docker image prune” command in order to delete any images that aren’t being used. With this article, we showed procedures and commands for how to delete docker images.

If you want to know more about Docker and have queries about it then you can contact SupportFly. It is one of the best docker consulting service providers with top-quality services and have certified admins to solve your problems. If you have any questions or come into any problems, you can contact our support team by clicking here.