当前位置: 首页 > news >正文

免费wordpress主题推荐标题优化

免费wordpress主题推荐,标题优化,百度指数移动版,北京网络公司有哪些文章目录 1. 安装 docker2. 配置 docker4. 配置域名解析5. 部署 registry6. Registry API 管理7. 批量清理镜像8. 其他 👋 这篇文章内容:实现shell 脚本批量清理docker registry的镜像。 🔔:你可以在这里阅读:https:/…

文章目录

  • 1. 安装 docker
  • 2. 配置 docker
  • 4. 配置域名解析
  • 5. 部署 registry
  • 6. Registry API 管理
  • 7. 批量清理镜像
  • 8. 其他

👋 这篇文章内容:实现shell 脚本批量清理docker registry的镜像。

🔔:你可以在这里阅读:https://github.com/Ghostwritten/registry-clean.git

1. 安装 docker

  • docker 安装

2. 配置 docker

$ cat /etc/docker/daemon.json 
{"exec-opts": ["native.cgroupdriver=systemd"],"insecure-registries": ["registry.ghostwritten.com"],"live-restore": true,"log-driver": "json-file","log-opts": {"max-size":  "100m","max-file": "5"}}# 配置代理
$ cat /usr/lib/systemd/system/docker.service.d/proxy.conf 
[Service]
Environment="HTTP_PROXY=http://192.168.21.101:7890"
Environment="HTTPS_PROXY=http://192.168.21.101:7890"
Environment="NO_PROXY=localhost,127.0.0.1,.coding.net,.tencentyun.com,.myqcloud.com,*.bsgchina.com"
$ systemctl daemon-reload && systemctl restart docker

4. 配置域名解析

服务端(192.168.21.2)配置

$ cat  /etc/unbound/unbound.conf
...local-data: "registry.ghostwritten.com A 192.168.21.25"local-data-ptr: "192.168.21.25 registry.ghostwritten.com"
....$ systemctl restart unbound

客户端

$ cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.21.2

5. 部署 registry

测试删除镜像

$ docker run -tid --restart=always --name registry -p 80:5000 -e REGISTRY_COMPATIBILITY_SCHEMA1_ENABLED=true -e REGISTRY_STORAGE_DELETE_ENABLED=true -v /data/registry:/var/lib/registry registry:latest

6. Registry API 管理


$ curl  -q -s   'http://registry.ghostwritten.com/v2/registry/tags/list' | jq .
{"name": "registry","tags": ["latest"]
}$ curl -I -X GET  'http://registry.ghostwritten.com/v2/registry/manifests/latest'
HTTP/1.1 200 OK
Content-Length: 6863
Content-Type: application/vnd.docker.distribution.manifest.v1+prettyjws
Docker-Content-Digest: sha256:f538bbbf8ff45e9872789dfcfbbcd48a44a9c87d21324595efb4df2e6b666c8c
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:f538bbbf8ff45e9872789dfcfbbcd48a44a9c87d21324595efb4df2e6b666c8c"
X-Content-Type-Options: nosniff
Date: Wed, 18 Sep 2024 09:02:51 GMT通过API直接匹配标签删除不掉镜像
$ curl -I -X DELETE  http://registry.ghostwritten.com/v2/registry/manifests/latest
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Wed, 18 Sep 2024 08:58:49 GMT
Content-Length: 98#获取ID
$ docker inspect registry.ghostwritten.com/registry:latest | jq -r '.[0].RepoDigests[]' |grep registry.ghostwritten.com | awk -F '@' '{print $2}'
sha256:4d2514be50520c34f3b207fc03dd734a9b72403624d8572f8c40e9185575e453$ curl -I -X GET  'http://registry.ghostwritten.com/v2/registry/manifests/sha256:4d2514be50520c34f3b207fc03dd734a9b72403624d8572f8c40e9185575e453'
HTTP/1.1 200 OK
Content-Length: 1363
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:4d2514be50520c34f3b207fc03dd734a9b72403624d8572f8c40e9185575e453
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:4d2514be50520c34f3b207fc03dd734a9b72403624d8572f8c40e9185575e453"
X-Content-Type-Options: nosniff
Date: Wed, 18 Sep 2024 09:12:51 GMT$ curl -I -X DELETE  'http://registry.ghostwritten.com/v2/registry/manifests/sha256:4d2514be50520c34f3b207fc03dd734a9b72403624d
8572f8c40e9185575e453'
HTTP/1.1 202 Accepted
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Wed, 18 Sep 2024 09:12:59 GMT
Content-Length: 0$ curl   -s   'http://registry.ghostwritten.com/v2/_catalog' | jq .
{"repositories": ["library/busybox","registry"]
}$ curl  -q -s   'http://registry.ghostwritten.com/v2/registry/tags/list' | jq .
{"name": "registry","tags": null
}$ rm -rf  /data/registry/docker/registry/v2/repositories/registry
$ curl -q -s http://registry.ghostwritten.com/v2/_catalog | jq .
{"repositories": ["library/busybox"]
}

推送镜像

$ docker push registry.ghostwritten.com/registry:latest
The push refers to repository [registry.ghostwritten.com/registry]
3715a40eaff0: Layer already exists 
e48d56ef719d: Layer already exists 
1670fc7fdd22: Layer already exists 
f3965cc04390: Layer already exists 
d62a02444d39: Layer already exists 
latest: digest: sha256:4d2514be50520c34f3b207fc03dd734a9b72403624d8572f8c40e9185575e453 size: 1363

查询镜像标签

$ curl  -q -s   'http://registry.ghostwritten.com/v2/registry/tags/list' | jq .
{"name": "registry","tags": ["latest"]
}

7. 批量清理镜像

首先,这是一个清理的演示,先批量推送镜像入库。未来应对可能存在各类情况。

  • 有没有项目名的镜像
  • 多个标签的镜像
$ cat registry-images-push.sh
docker push  registry.ghostwritten.com/demo/nginx:1.26
docker push  registry.ghostwritten.com/demo/nginx:latest
docker push registry.ghostwritten.com/library/busybox:1.36.1
docker push registry.ghostwritten.com/registry:latest
docker push registry.ghostwritten.com/library/busybox:1.35.0

推送镜像入库。

$ sh registry-images-push.sh

要删除的镜像我们存放到 registry-images-clean.txt 文件中。我们会检验以下几类删除场景。

  • 删除有个多个标签的镜像检验是否会误删除;
  • 删除没有项目名的镜像;
  • 删除不存在的镜像。
$ cat registry-images-clean.txt
registry.ghostwritten.com/library/busybox:1.36.1
registry.ghostwritten.com/registry:latest
registry.ghostwritten.com/demo/nginx:1.26
registry.ghostwritten.com/demo/nginx:noexist

这个脚本的目的是从Docker注册表中批量删除镜像。在执行脚本之前,必须创建一个名为images.txt的文件,其中应该包含计划删除的映像的名称。例如,文件中的一个条目可能如下所示:registry.demo.com/library/nginx:latest。

$ cat registry-images-clean.sh 
#!/bin/bash# Script Name: registry-images-clean.sh
# Author: ghostwritten
# Date: 2024-9-18
# Description: This script is designed to facilitate the batch deletion of images from a Docker registry. Prior to executing the script, you must create a file named images.txt, which should contain the names of the images scheduled for deletion. For example, an entry in the file might look like: registry.demo.com/library/nginx:latest. name=`basename $0 .sh`action=$1images_list() {image_repos=`cat registry-images-clean.txt  | awk -F '/' '{print $1}' |  uniq`for image_repo in $image_repos
do repositories=$(curl -q -s http://${image_repo}/v2/_catalog | jq -r '.repositories[]')if [[ -n $repositories ]] ; thenecho "$image_repo 镜像仓库列表:"for repo in $repositories; dotags=$(curl -q -s http://${image_repo}/v2/${repo}/tags/list | jq -r '.tags[]')if [ -z "$tags" ]; thenecho "  No tags found"elsefor tag in $tags; doecho "  $repo:$tag"donefidoneelseecho "$image_repo 镜像仓库是空库."fi
done}images_rm() {while IFS= read -r line
doimage_repo=$(echo "$line" | awk -F '/' '{print $1}')image_project=$(echo "$line" | awk -F '/' '{ if (NF > 2) print $(NF-1) "/"; else print "" }')image_name=$(echo "$line" | awk -F '/' '{print $NF}' | awk -F ':' '{print $1}')image_tag=$(echo "$line" | awk -F '/' '{print $NF}' | awk -F ':' '{print $2}')response=$(curl -s "http://${image_repo}/v2/${image_project}${image_name}/tags/list")if echo "$response" | jq -e ".tags | index(\"${image_tag}\")" > /dev/null; thenecho "镜像 ${image_project}${image_name}:${image_tag} 存在,准备删除..."source_data=`docker inspect registry | jq -r '.[0].Mounts[] | select(.Type == "bind") | .Source'`MANIFEST_DIGEST=`ls ${source_data}/docker/registry/v2/repositories/${image_project}${image_name}/_manifests/tags/${image_tag}/index/sha256/`curl -s -I -X DELETE  "http://${image_repo}/v2/${image_project}${image_name}/manifests/sha256:${MANIFEST_DIGEST}" 2>&1 > /dev/nullresponse=$(curl -s "http://${image_repo}/v2/${image_project}${image_name}/tags/list")if ! echo "$response" | jq -e '.tags | length > 0' > /dev/null; thenrm -rf ${source_data}/docker/registry/v2/repositories/${image_project}${image_name}fielseecho "镜像 ${image_repo}/${image_project}${image_name}:${image_tag} 不存在。"
fidone < registry-images-clean.txtdocker exec registry  bin/registry garbage-collect /etc/docker/registry/config.yml  >> /dev/null
docker restart registry}case $action inl|ls)images_list;;d|rm)images_rm;;*)echo "Usage: $name [ls|rm]"exit 1;;
esac
exit 0

首先,检查当前registry镜像仓库有哪些镜像。

$ sh registry-images-clean.sh ls
registry.ghostwritten.com 镜像仓库列表:demo/nginx:latestdemo/nginx:1.26library/busybox:1.35.0library/busybox:1.36.1registry:latest
registest.bsgchina.com 镜像仓库是空库.

现在,我们开始删除 registry-images-clean.txt 的镜像。

$  registry-images-clean.sh rm
镜像 library/busybox:1.36.1 存在,准备删除...
镜像 registry:latest 存在,准备删除...
镜像 demo/nginx:1.26 存在,准备删除...
镜像 registry.ghostwritten.com/demo/nginx:noexist 不存在。
镜像 demo/nginx:noexist 存在,准备删除...

执行结束后,再次检查镜像仓库列表。

sh registry-images-clean.sh ls
registry.ghostwritten.com 镜像仓库列表:demo/nginx:latestlibrary/busybox:1.35.0
registest.bsgchina.com 镜像仓库是空库.

8. 其他

  • 除了通过API 查看registry镜像列表,你可以部署一个 registry UI 查看镜像。
  • 另外,当你想要迁移一套具有自己镜像介质的镜像仓库。你可以参考这篇不需要推拉镜像的镜像仓库迁移教程。

参考:

  • Open Container Initiative Distribution Specification
  • https://docs.docker.com/registry/#introduction
  • https://github.com/Ghostwritten/registry-clean.git
http://www.hkea.cn/news/200849/

相关文章:

  • 做a高清视频在线观看网站济源新站seo关键词排名推广
  • 刚做的网站怎么搜索不出来百度seo收录软件
  • 视频拍摄app站长工具seo综合查询广告
  • 新闻单位建设网站的意义武汉seo推广优化
  • 低价网站公司软文怎么写
  • 东莞市建设公共交易中心网站百度官网首页
  • 如何建立的网站能争钱优化营商环境 助推高质量发展
  • 做百度网站营销型网站建设排名
  • 网站域名被黑国际新闻最新消息战争
  • 苏州网站开发公司济南兴田德润厉害吗网络自动推广软件
  • 广药网站建设试卷株洲最新今日头条
  • 网站建设管理考核办法微信推广平台怎么做
  • 网站新闻模块代码网络推广有哪些常见的推广方法
  • 合肥大型网站如何推广普通话
  • 高端网站制作软件怎么样推广自己的店铺和产品
  • 无障碍浏览网站怎么做关键词seo排名优化推荐
  • wordpress 247seo推广系统
  • 做深圳门户网站起什么名字好泰州seo外包公司
  • 网站视频上传怎么做百度站长平台论坛
  • wordpress农业模板下载小时seo
  • 做网站语言排名2018发帖推广哪个平台好
  • 销氪crmseo入门讲解
  • 蒙阴哪有做淘宝网站的钓鱼网站制作教程
  • 网站如何做导航条下拉菜单怎么做百度网页
  • 网站开发都做什么平台推广精准客源
  • 网站建设共享ip宁波seo搜索引擎优化
  • 学校网站建设必要性搜索引擎排名
  • 哪里有做区块链网站的百度网址大全在哪里找
  • 加盟平台网站怎么做竞价托管多少钱一个月
  • wordpress 微信 代码网站关键词怎么优化排名