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

Docker Registry Clean

在这里插入图片描述

文章目录

    • 1. Introduction
    • 2. Features
    • 3. Docker Installation
    • 4. Docker Configuration
    • 5. DNS Configuration
    • 6. Deploying the Registry
    • 7. Registry API Management
    • 8. Bulk Image Cleanup
    • 9. Additional Resources
    • 10. References

1. Introduction

registry-clean is a powerful and efficient solution designed to simplify the management of your Docker image registry. It enables easy bulk deletion of outdated or unnecessary images, ensuring your registry remains organized and performs optimally. This intuitive script simplifies image lifecycle management, providing peace of mind in fast-paced development environments. Enhance your Docker registry management experience with registry-clean.

2. Features

  • Handles Diverse Image Types: Deletes images with or without project names, images with multiple tags, and even non-existent images (reporting appropriately).
  • Safe Deletion: The script verifies the existence of images before deletion, preventing accidental removals.
  • Garbage Collection: Performs garbage collection after execution to reclaim disk space.

3. Docker Installation

Before proceeding, ensure Docker is installed and configured correctly.

  • Docker Installation Guide (Please replace this link with a current, official Docker installation guide.)

4. Docker Configuration

$ 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"
  }
}

If using a proxy, modify the /usr/lib/systemd/system/docker.service.d/proxy.conf file:

$ 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"

After configuration changes, run the following command:

$ sudo systemctl daemon-reload && sudo systemctl restart docker

5. DNS Configuration

To access the private image registry registry.ghostwritten.com, configure DNS resolution.

Server-side (192.168.21.25) Configuration: Modify the /etc/unbound/unbound.conf file, adding the following (adjust IP address as needed):

$ 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"
...

Restart the Unbound service:

$ sudo systemctl restart unbound

Client-side Configuration: Ensure the /etc/resolv.conf file points to the correct DNS server (e.g., your server at 192.168.21.2):

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

6. Deploying the Registry

Deploy the Docker Registry and enable image deletion:

$ docker run -d --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

Note: Create the /data/registry directory beforehand and ensure the Docker container has write permissions.

7. Registry API Management

The Docker Registry provides a RESTful API for image management. Here are some examples:

  • List Image Tags:
$ curl -s 'http://registry.ghostwritten.com/v2/registry/tags/list' | jq .
# Example output: {"name": "registry", "tags": ["latest"]}
  • Get Image Manifest:
$ curl -I -X GET 'http://registry.ghostwritten.com/v2/registry/manifests/latest'
# (HTTP response headers will be displayed here)
  • Delete Image (Using Digest): Direct tag deletion might fail; use the digest instead. First, obtain the image digest using docker inspect:
$ curl -I -X DELETE http://registry.ghostwritten.com/v2/registry/manifests/latest
# (HTTP response headers - likely a 400 error)

$ docker inspect registry.ghostwritten.com/registry:latest | jq -r '.[0].RepoDigests[]' | grep registry.ghostwritten.com | awk -F '@' '{print $2}'
# Output: (SHA256 digest)

$ curl -I -X GET 'http://registry.ghostwritten.com/v2/registry/manifests/<SHA256_digest>'
# (HTTP response headers)

$ curl -I -X DELETE 'http://registry.ghostwritten.com/v2/registry/manifests/<SHA256_digest>'
# (HTTP response headers - likely a 202 Accepted)

$ curl -s 'http://registry.ghostwritten.com/v2/_catalog' | jq .
# Example output: {"repositories": ["library/busybox", "registry"]}

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

$ rm -rf /data/registry/docker/registry/v2/repositories/registry

$ curl -q -s http://registry.ghostwritten.com/v2/_catalog | jq .
# Example output: {"repositories": ["library/busybox"]}

Pushing an image:

$ docker push registry.ghostwritten.com/registry:latest
# (Docker push output)

Checking image tags:

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

8. Bulk Image Cleanup

This section demonstrates a cleanup process. First, images are pushed to the registry. Future scenarios may need to handle various situations: images with or without project names, and images with multiple tags.

$ 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

Push images to the registry:

$ sh registry-images-push.sh

Images to be deleted are listed in registry-images-clean.txt. This tests several deletion scenarios: deleting images with multiple tags, images without project names, and non-existent images.

$ 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

The registry-images-clean.sh script is used for bulk deletion of Docker images. It supports two modes: ls (list images) and rm (remove images).

Usage:

  1. Create registry-images-clean.txt: List images to delete, one per line (e.g., registry.ghostwritten.com/library/busybox:1.36.1).
  2. Run the script:
    • List images: ./registry-images-clean.sh ls
    • Remove images: ./registry-images-clean.sh rm

Check current registry images:

$ sh registry-images-clean.sh ls
# Output: (List of images and tags)

Delete images:

$ sh registry-images-clean.sh rm
# Output: (Messages indicating success or failure for each image deletion)

Check the registry again:

$ sh registry-images-clean.sh ls
# Output: (Updated list of images and tags)

9. Additional Resources

  • Deploy a registry UI for easier management: Deploying a Registry UI (Please replace this link with a current, reliable guide.)
  • For migrating a registry: Registry Migration Tutorial (Please replace this link with a current, reliable guide.)

10. References

  • Open Container Initiative Distribution Specification
  • Docker Registry Documentation

Remember to replace the outdated links with current, official documentation. The registry-images-clean.sh script provided needs significant improvement for robustness and error handling in a production environment.

http://www.dtcms.com/a/106713.html

相关文章:

  • Scala的面向对象
  • 云巅之上:数字文明的重构与超越
  • C++进阶知识复习 16~30
  • bootloader+APP中,有些APP引脚无法正常使用?
  • 模拟医生会诊,四川大学华西医院团队开发多智能体对话框架助力疾病诊断
  • 【LINUX操作系统】通过System V看内核管理IPC资源
  • 经典算法 最大子段和
  • UE5学习笔记 FPS游戏制作37 蓝图函数库 自己定义公共方法
  • uni-app 框架 调用蓝牙,获取 iBeacon 定位信标的数据,实现室内定位场景
  • 求解传递闭包
  • 花洒洗澡完毕并关闭后过段时间会突然滴水的原因探究
  • 快速在 Windows 平台上高效安装flash_attn库
  • 【C++重点】std::map
  • STM32入门学习笔记(持续更新)
  • 如何使用Python通过STOMP协议接收ActiveMQ消息
  • The Rust Programming Language 学习 (九)
  • zkTLS 工作原理
  • 【C++初阶】--- string类
  • 23种设计模式-结构型模式-代理
  • jvm 的attach 和agent机制
  • 小白编程教程,编程设计中的三大程序控制结构,扣子平台的循环节点如何使用?扣子免费系列教程(26)
  • 质量和工艺之间的区别与联系?
  • 介绍 Docker 的基本概念和优势,以及在应用程序开发中的实际应用及数组讲解
  • 玛卡巴卡的k8s知识点问答题(七)
  • 2025年2月一区SCI-壮丽细尾鹩莺算法Superb Fairy-wren Optimization-附Matlab免费代码
  • 【C++继承】关于继承的细节分析
  • yolo11参数信息
  • 学习总结 网格划分+瞬态求解设置
  • vector模拟实现2
  • Windows系统服务器安装Office Online Server