【registry】CentOS7.x上docker registry v2的 镜像拉取推送、搜索、删除和垃圾回收

一、实验背景

【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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 CentOS 上使用 Podman 启动 Minikube 并遇到 "Error: initializing source docker://gcr.io/k8s-minikube/kicbase:v0.0.39: pinging container registry gcr.io: Get "https://gcr.io/v2/": dial tcp 74.125.23.82:443: i/o timeout" 错误,说明 Podman 无法从 `gcr.io` 上拉取镜像。 这个错误通常是由于网络连接问题导致的。你可以尝试以下解决方法: 1. 检查网络连接: 确保你的网络连接正常,并且可以访问互联网。尝试使用浏览器或其他网络工具访问 `https://gcr.io/v2/`,看看是否可以成功连接。 2. 检查防火墙设置: 检查你的系统防火墙或网络防火墙设置,确保允许与 `gcr.io` 的通信。如果有防火墙规则限制对特定 IP 或端口的访问,你可能需要相应地进行配置。 3. 使用代理: 如果你的网络使用代理,请确保 Podman 可以通过代理连接到 `gcr.io`。你可以设置相应的代理环境变量,以便 Podman 使用正确的代理配置。 ``` export HTTP_PROXY=http://proxy.example.com:port export HTTPS_PROXY=http://proxy.example.com:port ``` 将 `proxy.example.com` 和 `port` 替换为你的代理服务器和端口。 4. 更换镜像源: 如果你无法访问 `gcr.io`,可以尝试使用其他镜像源。你可以通过修改 Podman 的配置文件来指定其他镜像源,例如 Docker Hub 或其他私有镜像仓库。 首先,打开 Podman 的配置文件 `/etc/containers/registries.conf`: ``` sudo vi /etc/containers/registries.conf ``` 然后,将 `gcr.io` 替换为其他镜像源的地址。例如,将其替换为 Docker Hub 的地址: ``` [registries.search] registries = ['docker.io'] ``` 保存并关闭文件。然后重新启动 Podman 并尝试启动 Minikube。 如果问题仍然存在,请确保你的系统满足 Minikube 和 Podman 的最低要求,并参考 Minikube 和 Podman 的官方文档或社区支持寻求进一步的帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值