In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to delete docker-register image and none invalid image, the article is very detailed, has a certain reference value, interested friends must read it!
Background introduction
We all set up docker registry on the server, all the build images will be concentrated on one server, and over time the hard drive will be full. This article will focus on two cleaning methods. One is the image of the tag, and the other is to delete the docker physical image. The details are as follows:
Docker Mirror
Valid none image
To understand mirroring, we first need to understand how the Docker mirroring system works and how layers is organized.
When I pull a stresser image and run the docker images-a command, I will find that I have an extra one out of thin air
< none>:
< none>Mirror image.
➜docker images-aREPOSITORY TAG IMAGE ID CREATED SIZEstresser latest 68ee9b96793e 9 days ago 242MB dbcff8952263 9 days ago 242MB
When I want to delete this
< none>When mirroring, execute the following command, will prompt failure, I have to delete the stresser image to delete the image by the way.
➜docker rmi dbcff8952263Error response from daemon: conflict: unable to delete dbcff8952263 (cannot be forced)-image has dependent child images➜ docker rmi 68ee9b96793eUntagged: stresser:latestDeleted: sha256:68ee9b96793e0a3b3a77ec713f1bf4eb19446bd13fb933557dc401e452ca04c4Deleted: sha256:dbcff895226371eba2640c178414f5828aa5e6f417978b63ffa490d3865dc79aDeleted: sha256:875a0b6d28d1f52fc980a0948055d3ec3a38158ff7aa6a1a2c19c4243b96a57a ➜docker rmi dbcff8952263Error response from daemon: No such image: dbcff8952263:latest
: what is the mirror image for? We first look at the composition of the 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 the / var/lib/docker/graph directory by default, docker called layer database, in this example stresser consists of two layers (layer), we can find layers in the / var/lib/docker/graph directory.
When we pull stresser images, the first thing we download is dbcff8952263.
< none>The parent layer, and then the download stresser:latest,stresser consists of two layers. We can go to cat / car/lib/docker/graph/$ {containerId} / json and view the metadata of the image for more information (the following example is other container information)
{"id": "37dd4150474449629e8a7b576eed26cb8583d2fe5a3edf10fd84323dfd538678", "parent": "5cf74bcb1bde2e2249824a682f45235954543a5d57081db22c96402342db49e9", "created": "2017-04-06T16:28:35.51523979Z", "container_config": {"Hostname": "," Domainname ":", "User": "," Memory ": 0," MemorySwap ": 0," CpuShares ": 0," Cpuset ":"," AttachStdin ": false," AttachStdout ": false," AttachStderr ": false," PortSpecs ": null," ExposedPorts ": null," Tty ": false," OpenStdin ": false "StdinOnce": false, Env: null, "Cmd": ["/ bin/sh-c set-e" \ u0009NGINXGPGKEYA573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62;\ u0009 examples:\ u0009for server in\ u0009\ u0009ha.pool.sks-keyservers.net\ u0009\ u0009hkp://keyserver.ubuntu.com:80\ u0009\ u0009hkp://p80.pool.sks-keyservers.net:80\ u0009\ u0009pgp.mit.edu\ u0009; do\ u0009\ u0009echo\ "Fetching GPG key $NGINX_GPGKEY from $server\" \ u0009\ u0009apt-key adv-- keyserver\ "$server\"-- keyserver-options timeout=10-- recv-keys\ "$NGINX_GPGKEY\"\ u0026\ u0026 found=yes\ u0026\ u0026 break;\ u0009;\ u0009test-z\ "$found\"\ u0026\ u0026 echo\ u003e\ u00262\ "error: failed to fetch GPG key $NGINX_GPGKEY\"\ u0026\ u0026 exit 1 \ u0009exit 0 "]," Image ":"," Volumes ": null," WorkingDir ":"," Entrypoint ": null," NetworkDisabled ": false," MacAddress ":"," OnBuild ": null," Labels ": null}," author ":" NGINX Docker Maintainers\ "docker-maint@nginx.com\", "Size": 4901}
Finally, make a summary: an image is an intermediate image. We can use `image-a` to see that they will not cause the problem of occupying hard disk space (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>The mirror is dangling images, and this type can cause disk space consumption problems.
Programming languages like Java and Golang have a memory area that is not associated with any code. The garbage collection systems of these languages prioritize the space in this area and return it to 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, so we need a mechanism to clean up these suspended images.
We have already mentioned the effective
< none>Mirror images, they are a kind of middle layer, which is ineffective
< none>How did the mirror image appear? These dangling images are mainly generated by triggering the docker build and docker pull commands.
Use an example to explain:
Suppose we want to build a new image, the Dockerfile file is as follows
FORM Ubuntu:latestRUN echo 'hello world'
When we build docker build-t hello-world. /, a new image is generated.
But a month later, Ubuntu released a new image, and at this time we built a hello world image again, relying on the latest Ubuntu.
The problem is that we refer to the old hello-world image of Ubuntu, and at this time it will become an untagged dangling image! 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 for now we can only clean it up manually (just write a script).
Delete the image of the local hard disk
When our registry server has a lot of images of tag tags, but there is not enough hard disk space, we will want to delete the existing image to make room for the server. Registry comes with API interface to delete the image, but even if we call it, it is only a logical deletion, soft deletion (soft delete), just to remove the relationship between binary and the image. In fact, the image is always in our hard disk. We need a way to physically delete the stock space completely. There is a third-party solution on the Internet: delete-docker-registry-image. Next, list the operating steps and stop the registry service before operation.
Installation:
Curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee / usr/local/bin/delete_docker_registry_image > / dev/nullsudo chmod axix / usr/local/bin/delete_docker_registry_image
Set environment variable: data storage address:
The configuration of registry on my server is as follows:
Volumes:-/ root/docker-data/registry/data:/var/lib/registryroot@iZ94ft8hgzqZ:~/docker-data/registry/data/docker/registry/v2/repositories# ls-altotal 108drwxr-xr-x 27 root root 4096 Aug 21 18:29 .drw xr-xr-x 4 root root 4096 Oct 30 2015.. drwxr-xr-x 5 root root 4096 Mar 27 2016 exampledrwxr-xr-x 5 root root 4096 Mar 20 19:25 gitlab_ansibledrwxr-xr-x 5 root root 4096 Mar 22 2016 hlpays-jobdrwxr-xr -x 5 root root 4096 Jan 26 2016 hlpays-oadrwxr-xr-x 5 root root 4096 Mar 24 2016 hlpays-portaldrwxr-xr-x 5 root root 4096 Mar 27 18:32 ifex-crmexport REGISTRY_DATA_DIR=/root/docker-data/registry/data/docker/registry/v2
Logical deletion:
Delete_docker_registry_image-image tickets-dry-run; it's just logical deletion, it's useless, it's just a demonstration.
Root@iZ94ft8hgzqZ:~/docker-data/registry/data/docker/registry/v2/repositories# delete_docker_registry_image-- image tickets-- dry-runINFO [2017-09-13 18 would have deleted 21 dry-runINFO 04505] DRY_RUN: would have deleted / root/docker-data/registry/data/docker/registry/v2/blobs/sha256/27/27dedd9200ff607e76eb9d0e10beb103f53551e4ed39829d767cfbc208b79581INFO [2017-09-13 18 18 15 21 dry-runINFO 04506] DRY_RUN: would have deleted / root/docker-data/registry/data/docker/registry/v2/blobs/sha256/1b/1b2aade332a7133b1a03cae7695a3dcf9413dd017ff41f35a1bb1506becbacf3
Physical data deletion:
Delete the physical memory and you can see that the hard disk space is free.
Delete_docker_registry_image-image ticketsdf-h
Delete the specified label:
Delete_docker_registry_image-image testrepo/awesomeimage:supertag above are all the contents of the article "how to delete docker-register images and invalid none images". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.