一、实验背景
【registry】CentOS7.x上 registry server的安装使用
https://www.jianshu.com/p/69be934daa50
Docker也提供了Docker Registry来让大家搭建自己的私有镜像库。虽然它提供了删除的API,但是不好用。
Docker仓库在2.1版本中支持了删除镜像的API,但这个删除操作只会删除镜像元数据,不会删除层数据。在2.4版本中对这一问题进行了解决,增加了一个垃圾回收命令,删除未被引用的层数据。
有很多人抱怨说Docker Registry的删除功能并不会真正地释放空间。虽然官方提供了API,但那些都是软删除(soft delete),只是把二进制和镜像的关系解除罢了,并不是真正的删除。
那么,如果才能彻底实现镜像删除操作?
二、实验环境
操作系统: CentOS7.5 Minimal
registryServer: 192.168.1.105
registryClient: 192.168.1.102
在registryServer服务上
# docker run -it --rm registry sh -c "registry -v"
# systemctl status registry
# docker ps -a
# cat /etc/systemd/system/registry.service
# cat /opt/registry/config/config.yml
# ss -tan
浏览器访问:https://192.168.1.105/v2/_catalog
用户名密码: test/Test@123
在registryClient服务上
# docker login 192.168.1.105:443 -u test -p "Test@123"
# cat /root/.docker/config.json
# curl --help
# curl -s -X GET https://192.168.1.105:443/v2/_catalog
# curl -s -u test:Test@123 -X GET https://192.168.1.105:443/v2/_catalog
对用户名和密码,进行base64编码
# echo -n "test:Test@123" | base64
从上面可以看出,docker login 的用户名密码是通过base64编码,非加密存储在文件中的
携带认证信息发起请求,获取镜像列表
# curl -v -H "Authorization: Basic dGVzdDpUZXN0QDEyMw==" -X GET https://192.168.1.105:443/v2/_catalog
携带认证信息发起请求,获取镜像版本
# curl -H "Authorization: Basic dGVzdDpUZXN0QDEyMw==" -X GET https://192.168.1.105:443/v2/centos/tags/list
# curl -v -H "Authorization: Basic dGVzdDpUZXN0QDEyMw==" -X GET https://192.168.1.105:443/v2/centos/tags/list
获取指定版本镜像(centos:6)的sha256摘要
在registrySever服务上
# ll /opt/registry/
# ll /opt/registry/data/docker/registry/v2/repositories/centos/_manifests/revisions/sha256/
在registryClient服务上
# curl -u test:Test@123 --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -Is https://192.168.1.105/v2/centos/manifests/6
curl -u test:Test@123 --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -Is https://192.168.1.105/v2/centos/manifests/6 | awk '/Digest/ {print $NF}'
三、镜像拉取推送、搜索、删除和垃圾回收
shell脚本:https://github.com/IamMichael/registry-2.7.1.git
在registryServer服务上
查看帮助信息
# sh cleanRegistry.sh -h
查询仓库镜像
# sh cleanRegistry.sh -q
删除指定版本镜像
# sh cleanRegistry.sh -d centos:6 centos:7
删除指定镜像的所有版本
# sh cleanRegistry.sh -dd busybox
在registryClient服务上
查看帮助信息
# sh pullAndpush.sh -h
推送镜像
# sh pullAndpush.sh push centos:6
# sh pullAndpush.sh push centos:6 centos:7
拉取镜像
# sh pullAndpush.sh pull centos:6
# sh pullAndpush.sh pull centos:6 centos:7
四、清除仓库所有镜像
在registryServer服务上
# systemctl stop registry
# rm -rf /opt/registry/data/*
# systemctl start registry
# sh cleanRegistry.sh -q
五、参考
Docker Registry HTTP API V2
https://docs.docker.com/registry/spec/api
docker-registry-web
https://hub.docker.com/r/hyper/docker-registry-web
手把手教你搭建Docker Registry私服
https://blog.csdn.net/egworkspace/article/details/80518647
Registry configuration
https://github.com/docker/distribution/blob/master/docs/configuration.md
Docker Registry之删除镜像、垃圾回收
https://blog.csdn.net/u010884123/article/details/56838644
删除Docker Registry里的镜像怎么那么难
http://qinghua.github.io/docker-registry-delete
Docker Registry V1 to V2
http://dockone.io/article/747
Docker Registry镜像清理问题
https://ningyu1.github.io/site/post/46-docker-registry
docker-registry 私有仓库的搭建
https://www.cnblogs.com/elvi/p/8384604.html
docker registry 私有仓库镜像查询、删除、上传、下载
https://www.cnblogs.com/elvi/p/8384675.html
docker registry v2 API的使用
https://blog.csdn.net/kan2016/article/details/86105354
docker私有仓库删除image
https://blog.51cto.com/302876016/1966816
docker registry http api v2
https://blog.csdn.net/ztsinghua/article/details/51496658
What is the difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1 ?
https://unix.stackexchange.com/questions/70963/difference-between-2-2-dev-null-dev-null-and-dev-null-21