docker registry 鏡像刪除

registry:2.5.0版本的鏡像,將鏡像默認存放在了/var/lib/registry 目錄下 
/var/lib/registry/docker/registry/v2/repositories/ 目錄下會有幾個文件夾,命名是已經上傳了的鏡像的名稱。 
若是須要刪除已經上傳的鏡像,現有兩種方法docker

1.官方推薦版重點內容json

1) 更改registry容器內/etc/docker/registry/config.yml文件markdown

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

2) 找出你想要的鏡像名稱的tagapp

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

3) 拿到digest_hash參數curl

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

如:wordpress

$ 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) 複製digest_hashpost

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

5) 刪除清單url

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

如:.net

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

6) 刪除文件系統內的鏡像文件,注意2.4版本以上的registry纔有此功能code

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

如:

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

2.簡易版 
1.打開鏡像的存儲目錄,若有-V操做打開掛載目錄也能夠,刪除鏡像文件夾

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

2.執行垃圾回收操做,注意2.4版本以上的registry纔有此功能

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

重啓

相關文章
相關標籤/搜索