registry:2.5.0版本的鏡像,將鏡像默認存放在了/var/lib/registry 目錄下 /var/lib/registry/docker/registry/v2/repositories/ 目錄下會有幾個文件夾,命名是已經上傳了的鏡像的名稱。
如果需要刪除已經上傳的鏡像,現有兩種方法
1.官方推薦版重點內容
1) 更改registry容器內/etc/docker/registry/config.yml文件
storage:
delete:
enabled: true
- 1
- 2
- 3
- 4
2) 找出你想要的鏡像名稱的tag
$ curl -I -X GET <protocol>://<registry_host>/v2/<鏡像名>/tags/list
- 1
- 2
3) 拿到digest_hash參數
$ curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://<倉庫地址>/v2/<鏡像名>/manifests/<tag>
- 1
- 2
如:
$ 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_hash
Docker-Content-Digest: <digest_hash>
- 1
- 2
5) 刪除清單
$ curl -I -X DELETE <protocol>://<registry_host>/v2/<repo_name>/manifests/<digest_hash>
- 1
- 2
如:
$ curl -I -X DELETE http://10.109.252.221:5000/v2/wordpress/manifests/sha256:b3a15ef1a1fffb8066d0f0f6d259dc7f646367c0432e3a90062b6064f874f57c
- 1
- 2
6) 刪除文件系統內的鏡像文件,注意2.4版本以上的registry才有此功能
$ 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
