docker registry image deletion

Registry: The image of version 2.5.0, the image is stored in the /var/lib/registry directory by  default
/var/lib/registry/docker/registry/v2/repositories/ , there will be several folders in the directory, and the name is the name of the image that has been uploaded. 
If you need to delete the uploaded image, there are two methods

1. Key content of the official recommended version

1) Change the /etc/docker/registry/config.yml file in the registry container

storage:
  delete:
    enabled: true
  • 1
  • 2
  • 3
  • 4

2) Find the tag of the image name you want

$ curl -I -X GET <protocol>://<registry_host>/v2/<镜像名>/tags/list
  • 1
  • 2

3) Get the digest_hash parameter

$ curl  --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://<仓库地址>/v2/<镜像名>/manifests/<tag>
  • 1
  • 2

Such as:

$ curl  --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://10.109.252.221:5000/v2/wordpress/manifests/latest
  • 1
  • 2

4) Copy digest_hash

Docker-Content-Digest: <digest_hash>
  • 1
  • 2

5) Delete list

$ curl -I -X DELETE <protocol>://<registry_host>/v2/<repo_name>/manifests/<digest_hash>
  • 1
  • 2

Such as:

$ curl -I -X DELETE http://10.109.252.221:5000/v2/wordpress/manifests/sha256:b3a15ef1a1fffb8066d0f0f6d259dc7f646367c0432e3a90062b6064f874f57c
  • 1
  • 2

6) Delete the image file in the file system, note that the registry of version 2.4 and above only has this function

$ docker exec -it <registry_container_id> bin/registry garbage-collect <path_to_registry_config>
  • 1
  • 2

Such as:

$ docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml
  • 1
  • 2

2. Simple version 
1. Open the storage directory of the mirror, if you have -V operation to open the mount directory, you can delete the mirror folder

$ docker exec <容器名> rm -rf /var/lib/registry/docker/registry/v2/repositories/<镜像名>
  • 1
  • 2

2. Perform garbage collection operations. Note that only registry versions above 2.4 have this function.

$ docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml
  • 1
  • 2

reboot

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/l6807718/article/details/52886546

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324971624&siteId=291194637