kubreretes && docker 模块
kubreretes
https://www.cnblogs.com/zhangb8042/p/11444756.html
docker
https://docker-py.readthedocs.io/en/stable/images.html#docker.models.images.Image
#!/usr/bin/env python import docker import os import argparse import logging parser = argparse.ArgumentParser(description="遍历目录下所有.tar.gz文件Load镜像") parser.add_argument("--path", type=str, default="./", required=True, help="指定镜像文件存储路径") parser.add_argument("--label", type=str, nargs="*", default=[], action="store", help="指定需要删除的标签") parser.add_argument("--registry", type=str, default="lanceyuan", required=True, help="指定仓库地址") args = parser.parse_args() PATH = args.path REGISTRY = args.registry DEL_FLAG = args.label DOCKER_SOCK = "unix://var/run/docker.sock" VERSION = "1.38" LOGFILE = "" def logs(): logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) fh = logging.FileHandler(LOGFILE, mode="a") ch = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') fh.setFormatter(fmt=formatter) ch.setFormatter(fmt=formatter) logger.addHandler(fh) logger.addHandler(ch) return logger client = docker.DockerClient(base_url=DOCKER_SOCK, version=VERSION) files_list = os.listdir(PATH or "/home") for item in files_list: if item.endswith(".tar.gz"): with open("{}".format(os.path.join(PATH, item.strip())), "rb") as f: try: image = client.images.load(f.read()) except Exception as e: print(e) if image[0].tags: old_image_name = image[0].tags[0] _, image_name = old_image_name.split("/") for flag in DEL_FLAG: image_name = image_name.replace(flag.lower(), "") new_image_name = "{}/{}".format(REGISTRY, image_name) image[0].tag(new_image_name) print("\033[1;32;40m{}\033[0m".format(new_image_name.ljust(30)), end=" ") print(image[0].id) try: client.images.remove(old_image_name) client.images.push(new_image_name) except Exception as e: print(e) else: old_image_name = image[0].short_id new_image_name = item.replace(".tar.gz", "") image[0].tag("{}/{}".fromat(REGISTRY, new_image_name)) try: client.images.push("{}/{}".fromat(REGISTRY, new_image_name)) print("\033[1;32;40m{}\033[0m".format(new_image_name.ljust(30)), end=" ") print(image[0].id) except Exception as e: print(e) print("\033[1;31;40m{}\033[0m".format(old_image_name.ljust(30)), end=" ") print(image[0].id)
venv/bin/python3.5 loadImages.py --path /opt/Congo_hotfix14/images/ --label test-nb --registry 172.16.99.59:5000
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· SQL Server 内存占用高分析
· .NET Core GC计划阶段(plan_phase)底层原理浅谈
· .NET开发智能桌面机器人:用.NET IoT库编写驱动控制两个屏幕
· 我干了两个月的大项目,开源了!
· 推荐一款非常好用的在线 SSH 管理工具
· 千万级的大表,如何做性能调优?
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· .NET周刊【1月第1期 2025-01-05】