Delete the local image in Docker
This article will introduce how to delete local images in Docker.
Delete unused and dangling local images in Docker
Suppose that besides having untagged docker images, you also have unused images and some containers that you also want to delete. In this case, choose the command shown below.
$ docker system prune -a
This command will prompt a warning to let you know that if you select Yes, this command will:
- Delete all stopped containers;
- Remove all networks that are not used by at least one container;
- Remove all images that do not have at least one container associated with them;
- Delete all caches.
However, if this command doesn't fit what you need to accomplish, and you just want to remove:
- Unlabeled or dangling mirror images;
- Stopped container;
- Dangling cache;
- The network is not used by at least one container.
In this case, use prune
the command without including -a
the tag, as shown below.
$ docker system prune
Delete a specific local image in Docker
We may also want to remove a specific image from our local system and keep all other files intact.
In this case, we need the image ID of a specific image that we want to remove. We can access this through the Images page in the Docker Desktop application.
We can also access the image ID using our terminal or Docker CLI by running the following command.
isaactonyloi@DESKTOP-HV44HT6:~$ docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c316d5a335a5 3 weeks ago 142MB
Now that we have the image ID, we can docker rmi
remove that specific image using the remove command appended to the image ID as shown below.
$ docker rmi c316d5a335a5
Output:
Untagged: nginx:latest
Untagged: nginx@sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767
Deleted: sha256:c316d5a335a5cf324b0dc83b3da82d7608724769f6454f6d9a621f3ec2534a5a
Deleted: sha256:67e568696593c33b4a15c9d81dc6f67499b8d973b88eb49b53d47bf4dbf4d187
Deleted: sha256:0f8d4e3d979c540644f248b4206cf540978166b095223bdc950628dca2e8f3f1
Deleted: sha256:5d75bfe8a7422476a495b27c8a1598d1206137631d350b8bdee13bc88f365282
Deleted: sha256:8284a9e28c625b2826efdd6160ea1ff7f710881a4a2afe1ef58a5eb51d3f919e
Deleted: sha256:89a1db9e1079b7574c1a707bc8c1fe04ff723bc71d4bca8bc48653e9a32186d2
Deleted: sha256:7d0ebbe3f5d26c1b5ec4d5dbb6fe3205d7061f9735080b0162d550530328abd6
Use filters in Docker to remove untagged local images
We can also use filters and wildcards to identify dangling images, that is, images that are not associated with any container. We can use filter tags -f
to find images that meet the conditions dangling=true
.
The command below should list all images not associated with any container. However, note that if you do not have untagged images on your system, the command will only return the headers.
$ docker images -a -f dangling=true
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c316d5a335a5 3 weeks ago 142MB
Delete all local images in Docker
-a
When used
with the tag, -q
the tag allows us to retrieve and list all image IDs in the local system.
$ docker images -a -q
54c9d81cbb44
c316d5a335a5
Using this command, we can list docker rmi
all the images under to remove all images from our system. This is how we can nest this command to eliminate all images.
$ docker rmi $(docker images -a -q)
Output:
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:669e010b58baf5beb2836b253c1fd5768333f0d1dbcb834f7c07a4dc93f474be
Deleted: sha256:54c9d81cbb440897908abdcaa98674db83444636c300170cfd211e40a66f704f
Deleted: sha256:36ffdceb4c77bf34325fb695e64ea447f688797f2f1e3af224c29593310578d2
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Git list remote branches
Publish Date:2025/04/20 Views:54 Category:OPERATING SYSTEM
-
This article will show you how to list remote repositories from your local branch. A remote repository is a project hosted on a server, such as Github/Gitlab. git remote Allows us to use short names (aliases) to execute commands instead of
Pushing from an existing remote repository to another remote repository in Git
Publish Date:2025/04/20 Views:67 Category:OPERATING SYSTEM
-
This tutorial will teach you how to push from an existing remote repository to a different remote repository in Git. Git is a version control system used to track changes in a project directory. Git uses commits for such purposes. In Git, y
Update the repository remotely by setting
Publish Date:2025/04/20 Views:120 Category:OPERATING SYSTEM
-
In this tutorial, we will discuss how to set up the central repository as a remote for our local repository so that our branch is updated whenever the central repository changes. We should always perform this step before making edits to our
Rename Git repository
Publish Date:2025/04/20 Views:100 Category:OPERATING SYSTEM
-
In this article, we will discuss renaming Git repositories. We can explain this in different ways. It can rename the displayed name, the repository on GitHub, or the folder of the repository. We will discuss these and go through the steps w
Creating tags in a Git repository
Publish Date:2025/04/20 Views:117 Category:OPERATING SYSTEM
-
In this tutorial, we will discuss how to create tags in a Git repository. Creating tags in a Git repository In Git, we may want to mark certain commits or specific points in the history of the project repository. To do this, we can use the
Push Git tags to remote repositories
Publish Date:2025/04/20 Views:177 Category:OPERATING SYSTEM
-
If you create a git tag locally, your intention must be to share your changes with your team for easy tracking. Commit is one of the common operations to share changes. But another sharing and tracking idea added to it is Git Tags. This art
Fixed: Git Is Not Recognized as an Internal or External Command error
Publish Date:2025/04/20 Views:198 Category:OPERATING SYSTEM
-
This article discusses three methods we can use to fix "git" Is Not Recognized as an Internal or External Command when using Git in the Windows Command Prompt . This is a frequently reported error by users who prefer running Git commands on
Ignore untracked files in Git
Publish Date:2025/04/20 Views:162 Category:OPERATING SYSTEM
-
This article will discuss two methods that can be used to ignore untracked files in a Git repository. If there are multiple untracked files and folders in your local repository, running the git status command will output many lines. Let’s
Ignore everything except certain files in Git
Publish Date:2025/04/20 Views:151 Category:OPERATING SYSTEM
-
This article outlines the steps to make Git ignore all but a few files in a Git repository. The .gitignore file is a useful Git utility that allows us to tell Git which files to track and which files not to track. If you want your .gitignor