Reputation: 259
here is my input and output:
shshenhx@shshenhx:~/Desktop/Docker$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python latest 336d482502ab 4 days ago 692 MB
shshenhx@shshenhx:~/Desktop/Docker$ docker rmi 336
Untagged: python:latest
Untagged: python@sha256:bf0718e2882cabc144c9c07d758b09c65efc104a6ddc72a9a976f8b26f67c2ee
Deleted: sha256:336d482502ab564b0b2964b2ed037529ba40c7b4ade2117ca11d74edbf11f99e
Deleted: sha256:1e2f72b0bf844de7bfe57a32115b660770355843ef8078fb55629e720147e6a9
Deleted: sha256:b5818ba96f33835318f3e9d7b4094e1007be247f04ab931ea9ef83b45b451f90
Deleted: sha256:0c2d7cafdab1084ebbd0112b3bedf76458ae6809686fb0ad9bae8022f11c3a84
shshenhx@shshenhx:~/Desktop/Docker$ docker pull python
Using default tag: latest
latest: Pulling from library/python
4176fe04cefe: Already exists
851356ecf618: Already exists
6115379c7b49: Already exists
aaf7d781d601: Already exists
40cf661a3cc4: Already exists
975fe2fd635f: Pull complete
bf4db784e7fd: Pull complete
0491f7e9426b: Pull complete
Digest: sha256:bf0718e2882cabc144c9c07d758b09c65efc104a6ddc72a9a976f8b26f67c2ee
Status: Downloaded newer image for python:latest
My question is, I have already rm python image, why it still shows already exist for some of layers? How can I totally delete all the python layers. Thanks.
Upvotes: 19
Views: 19614
Reputation: 270
For someone interested in: (1) using the command line; (2) removing cache only for images that have been removed with docker rmi
(i.e., not visible with docker images --all
), but for which caches are still present, and for which the Already exists
shows for layers when pulling image; you can try this command:
docker builder prune
(It may take up to 15 minutes to run this command, so be patient.)
This command seems to have solved the problem for me. I did not want to use the general, "system-wide" prune
/ purge
/ clean docker commands and functionalities, because I had some images and containers running (not related to the image that I have already removed), that I wished to have left as they were.
Source of the solution: https://forums.docker.com/t/how-to-delete-cache/5753/7
I think that the situation of "invisible" cached layers for images removed with docker rmi
may happen due to the fact of using docker compose (as suggested also by John Doe in his comment to one of the answers in the current question: docker pull always show "Already exists" for layers during pull even after deleting all images).
Upvotes: 3
Reputation: 61
You can use docker system prune
but it will clear everything in docker.
Its not an image problem its actually cache problem so deleting your images wont work because the problem relies in layer caching.
There is a --no-cache flag in docker build but I don't know if it works with docker pull too.
Upvotes: 3
Reputation: 77
docker system prune -a
helped me.It will remove both unused and dangling images.
Upvotes: 4
Reputation: 3959
There is a docker command that deletes images that do not have an associated running container:
docker image prune
docker image prune -a
docker image prune -a --filter "until=48h"
You can add the -f or --force flag to prune the images and not prompt for confirmation
You could use this in a scheduled bash script to keep your drive tidy
Upvotes: 1
Reputation: 311
What helped for me was to run docker-system prune
after removing all containers and images. So the whole process I got it to work was:
docker rm -vf $(docker ps -a -q)
docker rmi -f $(docker images -a -q)
docker system prune
Upvotes: 4
Reputation: 2576
Docker has a solution for this on docker dashboard, just press the button below and presto it works! (This is in the troubleshooting section. or the bug icon)
Upvotes: 2
Reputation: 543
So after a lot of searching, I have a solution although I don't think it's necessarily a great one.
The "sledge hammer solution" would be to do:
rm -rf /var/lib/docker
This basically factory resets docker, so you would lose everything. This was fine for my case, but be very careful and think this through before using this one.
Upvotes: 0
Reputation: 57
Please try this command docker rmi 336d482502ab
and then try to pull it again.
Upvotes: -1
Reputation: 3596
From reference of docker images command
Docker images have intermediate layers that increase reusability, decrease disk usage, and speed up docker build by allowing each step to be cached. These intermediate layers are not shown by default.
Maybe those Already exists
are intermediate layers. By default, they are hided when you run docker images
, please try docker images --all
.
Upvotes: 3