Skip to main content

智能Docker镜像拉取工具 - 自动选择最优镜像源

Project description

DockerPull 智能镜像拉取工具

🚀 介绍

DockerPull 是一个智能的 Docker 镜像拉取工具,能够自动检测并使用最优的镜像加速源,解决 Docker 镜像拉取慢或失败的问题。

✨ 主要特性

  • 智能镜像源选择: 自动检测 20+ 个可用镜像加速源,选择最优源进行拉取
  • 实时进度显示: 显示镜像拉取的实时进度(Downloading/Extracting/Pulling)
  • 调试模式: 支持 -d 参数输出实际执行的完整命令,便于调试
  • 耗时统计: 自动统计并显示整个拉取过程的总耗时
  • 容错机制: 支持重试机制,单个镜像源失败自动切换到下一个
  • 命令行友好: 使用 argparse 标准库,支持完整的命令行参数和帮助

📦 安装

系统要求

  • Python 3.6+
  • Docker 已安装

快速安装

# 克隆仓库
git clone https://gitee.com/your-repo/docker-pull.git
cd docker-pull

# 安装依赖(如果有的话)
pip install -r requirements.txt

🎯 使用方法

基本用法

# 拉取镜像(自动选择最优镜像源)
python docker_pull_smart.py nginx:latest

# 拉取指定版本
python docker_pull_smart.py python:3.9

# 列出所有可用镜像源
python docker_pull_smart.py --list-mirrors

# 列出本地镜像
python docker_pull_smart.py --local-images

高级用法

# 调试模式 - 显示实际执行的完整命令
python docker_pull_smart.py nginx:latest -d

# 设置超时时间(秒)
python docker_pull_smart.py nginx:latest --timeout 600

# 设置最大重试次数
python docker_pull_smart.py nginx:latest --max-retries 5

# 组合使用
python docker_pull_smart.py nginx:latest -d --timeout 600 --max-retries 5

命令行参数

positional arguments:
  image_name            要拉取的镜像名称,如 nginx:latest

options:
  -h, --help            显示帮助信息
  --list-mirrors        列出所有可用的镜像源
  --local-images        列出本地Docker镜像
  --timeout TIMEOUT     Docker命令超时时间(秒),默认300秒
  --max-retries MAX_RETRIES
                        每个镜像源的最大重试次数,默认3次
  -d, --debug           调试模式,输出实际执行的完整命令

🎨 输出示例

正常拉取模式

🎯 开始智能拉取镜像: nginx:latest
==================================================
📋 找到 22 个可用镜像源
  1. 阿里云镜像仓库 - https://registry.cn-hangzhou.aliyuncs.com
  2. 网易云镜像仓库 - https://hub-mirror.c.163.com
  ...

🔄 尝试镜像源 1/22: 阿里云镜像仓库
🔗 URL: https://registry.cn-hangzhou.aliyuncs.com
📥 Downloading  6e7cb3f1d8a5:  45.67MB/123.45MB
📥 Extracting  6e7cb3f1d8a5:  100%
✅ 成功拉取镜像: nginx:latest
==================================================
🎉 镜像拉取成功: nginx:latest
📍 使用的镜像源: 阿里云镜像仓库
⏱️  总耗时: 15.3秒

调试模式

🎯 开始智能拉取镜像: nginx:latest
==================================================
🔍 执行命令: docker pull https://registry.cn-hangzhou.aliyuncs.com/nginx:latest
📥 Downloading  6e7cb3f1d8a5:  45.67MB/123.45MB
📋 latest: Pulling from library/nginx
📋 Digest: sha256:1234567890abcdef...
✅ 命令执行成功: docker pull https://registry.cn-hangzhou.aliyuncs.com/nginx:latest (耗时: 12.5秒)
✅ 成功拉取镜像: https://registry.cn-hangzhou.aliyuncs.com/nginx:latest
🏷️  设置镜像标签: https://registry.cn-hangzhou.aliyuncs.com/nginx:latest -> nginx:latest
✅ 成功设置镜像标签: nginx:latest
🗑️  删除镜像: https://registry.cn-hangzhou.aliyuncs.com/nginx:latest
==================================================
🎉 镜像拉取成功: nginx:latest
📍 使用的镜像源: 阿里云镜像仓库
⏱️  总耗时: 15.3秒

🔧 技术特性

  • 智能镜像源管理: 实时检测镜像源可用性,自动过滤失效源
  • 实时输出: 使用 subprocess.Popen 实现实时进度显示
  • 错误处理: 完善的异常处理和重试机制
  • 跨平台: 支持 Windows、Linux、macOS
  • 标准库: 使用 argparse 标准库,无需额外依赖

🤝 参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

📄 许可证

MIT License - 详见 LICENSE 文件


相关链接

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dps_liumou_stable-1.0.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dps_liumou_stable-1.0.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file dps_liumou_stable-1.0.0.tar.gz.

File metadata

  • Download URL: dps_liumou_stable-1.0.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for dps_liumou_stable-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6fd87d103ec0c27ea6c5fdf3d7ee917cd80040d41b5fa0c9a7f764fcb6d76a92
MD5 d711c52f6aeb8fec2c5ff606ccd68c6d
BLAKE2b-256 3cf063fb23232b2f5aa24714b549b7138ea39e85910f837f48d2742da8aa3ed1

See more details on using hashes here.

File details

Details for the file dps_liumou_stable-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dps_liumou_stable-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 798f579592d924e98eb02382443eb2847c72513dff681fb7d93e7b05049a9703
MD5 00ae9690e9e6d77d5ad40e2604dd2fef
BLAKE2b-256 868d91ce154afae1e88429f146c73c1ac7b9591b584c7db8beb22d1f2ea49c6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page