background
Accidentally found that there are many images on the server, taking up a lot of space, want to clean it up
results delete directly and report an error
docker rmi 8f5116cbc201
Error response from daemon: conflict: unable to delete 8f5116cbc201 (cannot be forced) - image has dependent child images
Then, there are two main methods of online demand
Method 1: forcibly delete the image
docker rmi -f 8f5116cbc201
Error response from daemon: conflict: unable to delete 8f5116cbc201 (cannot be forced) - image has dependent child images
End in failure
Method 2: Bulk delete containers, then delete the image
# Stop all containers
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop
# Delete all containers
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm
# Delete all none images
docker images|grep none|awk '{print $3 }'|xargs docker rmi
Or end in failure
Why
after searching for a long time, it is found that the problem is due to tag, that is, there are other images from this image. You can use the following command to list the parent images of all images created after the specified image
scheme
query dependency first
docker image inspect — format = ‘{. Repotags} {. ID} {. Parent}’ $(docker image LS – Q — filter since = XXX) # XXX refers to the image ID
and then delete the container according to tag
docker rm REPOSITORY:TAG
supplement
Docker none image
Effective none image
the composition of docker file system, docker image is composed of many layers, each layer has a parent-child relationship, all docker file system layers are stored in/var/lib/docker/graph directory by default, docker is called layer database
Finally, make a summary < none>:< none> Image is a kind of intermediate image. We can use docker images – A to see that they will not cause the problem of hard disk space occupation (because this is the parent layer of the image and must exist), but it will confuse our judgment
Invalid none image
Another type of < none>:< none> Images are dangling images, which can cause disk space occupation problems
Programming languages like Java and golang have a memory area that is not associated with any code. The garbage collection system of these languages first reclaims the space of this area and returns it to the heap memory, so this memory area is useful for later memory allocation
Docker’s dangling file system is similar to the above principle. It is not used and will not be associated with any images. Therefore, we need a mechanism to clean up these dangling images
We have mentioned effective < none> Mirror image, they are a kind of middle layer, which is invalid < none> How does the mirror image appear? These dangling images are mainly generated by triggering the docker build and docker pull commands
Use the following command to clean up
docker RMI $(docker images – F “dangling = true” – Q)
docker does not have an automatic garbage collection mechanism, which may be improved in the future, but at present we can only clean it manually (just write a script)
Similar Posts:
- [Solved] Docker rmi Error: Error response from daemon: conflict: unable to delete 6c20ffa54f86 (must be forced) – image is being used by stopped container 6e81c0d9b6ab
- docker: Error response from daemon: Conflict. The container name “/xx” is already in use
- Docker port is already allocated [How to Solve]
- [Solved] Bind for 0.0.0.0:80 failed: port is already allocated
- Failed to get D-Bus connection: Operation not permitted [docker Install centos7]
- Java.lang.outofmemoryerror: permgen space and its solution in eclipse + Maven environment
- How to Solve Error during connect when installing docker in Windows 10
- SAP work process Memory allocate
- How to Close the iframe Window opened by layui
- [Solved] cannot kill Docker container – permission denied