Docker Tutorial: How to Delete an Image
Summary: This article will show you how to use Docker commands to delete images. We will use specific cases and detailed command explanations to help you easily delete Docker images that are no longer needed.
When using Docker, we often need to delete images that are no longer used or no longer needed. Docker provides simple and powerful commands to delete images, let's learn how to use these commands together.
Step 1: View available mirrors
Before deleting a mirror, we first need to view the currently available mirrors. Use the following command to list all mirrors on your system:
docker images
This will display a table with the image's name, tags, image ID, creation time, and size.
Step 2: Delete a single image
If you only want to delete a specific image, you can use the following command:
docker rmi IMAGE_NAME_OR_ID
where IMAGE_NAME_OR_ID
is the name or ID of the image to delete. For example, to delete my_image
an image named , you can run the following command:
docker rmi my_image
Step 3: Forcefully delete the mirror
Sometimes, an image may be used by one or more containers, at this time you need to forcibly delete the image. Use the -f
or --force
option to force delete the image, even if there are containers using it. The following is an example of a command using the force delete option:
docker rmi -f IMAGE_NAME_OR_ID
For example, to forcefully remove my_image
an image named , you can run the following command:
docker rmi -f my_image
Step 4: Delete Multiple Mirrors
If you want to delete multiple images at once, you can specify multiple image names or IDs in the command. The following is an example command to delete multiple mirrors:
docker rmi IMAGE_NAME_OR_ID1 IMAGE_NAME_OR_ID2
For example, to delete two images named image1
and , you can run the following commands:image2
docker rmi image1 image2
Step 5: Remove all mirrors
If you need to delete all images, including intermediate images that are not used by any containers, you can use the -a
or --all
option. The following is an example command to delete all mirrors:
docker rmi -a
Note that deleting all images is irreversible and will delete all images on the system, including intermediate images.