https://github.com/sky22333/hubproxy

引用原文介绍:

自托管轻量级、高性能的多功能代理加速服务,提供 Docker 镜像加速、GitHub 加速、下载离线镜像等功能。一个二进制文件实现所有功能,支持仓库审计。流式转发,无缓存。

✨ 特性

  • 🐳 Docker 镜像加速 - 支持 Docker Hub、GHCR、Quay 等多个镜像仓库加速,流式传输优化拉取速度。

  • 🐳 离线镜像包 - 支持下载离线镜像包,流式传输加防抖设计。

  • 📁 GitHub 文件加速 - 加速 GitHub Release、Raw 文件下载,支持api.github.com,脚本嵌套加速等等

  • 🤖 AI 模型库支持 - 支持 Hugging Face 模型下载加速

  • 🛡️ 智能限流 - IP 限流保护,防止滥用

  • 🚫 仓库审计 - 强大的自定义黑名单,白名单,同时审计镜像仓库,和GitHub仓库

  • 🔍 镜像搜索 - 在线搜索 Docker 镜像

  • 轻量高效 - 基于 Go 语言,单二进制文件运行,资源占用低。

  • 🔧 统一配置 - 统一配置管理,便于维护。

  • 🛡️ 完全自托管 - 避免依赖免费第三方服务的不稳定性,例如cloudflare等等。

  • 🚀 多服务统一加速 - 单个程序即可统一加速 Docker、GitHub、Hugging Face 等多种服务,简化部署与管理。

其支持的特性能覆盖大部分使用场景。

Docker Compose

services:
  hubproxy:
    image: ghcr.io/sky22333/hubproxy
    container_name: hubproxy
    restart: always
    ports:
      - "5000:5000"
    volumes:
      - ./src/config.toml:/root/config.toml
    logging:
      driver: json-file
      options:
        max-size: "1g"
        max-file: "2"

要注意的一点就是,官方提供的docker-compose映射配置文件,需要提前在对应目录创建对应的空白文件,否则docker启动时会创建一个空文件夹导致映射文件出错导致的启动失败。

使用

Docker

# 原命令
docker pull nginx

# 使用加速
docker pull yourdomain.com/nginx

# ghcr加速
docker pull yourdomain.com/ghcr.io/sky22333/hubproxy

# 符合Docker Registry API v2标准的仓库都支持

当然也支持配置为全局镜像加速,在主机上新建(或编辑)/etc/docker/daemon.json

"registry-mirrors" 中加入域名:

{
  "registry-mirrors": [
    "https://yourdomain.com"
  ]
}

若已设置其他加速地址,直接并列添加后保存,再执行 sudo systemctl restart docker 重启docker服务让配置生效

GitHub 文件加速

# 原链接
https://github.com/user/repo/releases/download/v1.0.0/file.tar.gz

# 加速链接
https://yourdomain.com/https://github.com/user/repo/releases/download/v1.0.0/file.tar.gz

# 加速下载仓库
git clone https://yourdomain.com/https://github.com/sky22333/hubproxy.git

配置文件

config.toml 配置说明

[server]
host = "0.0.0.0"
# 监听端口
port = 5000
# Github文件大小限制(字节),默认2GB
fileSize = 2147483648
# HTTP/2 多路复用,提升下载速度
enableH2C = false

[rateLimit]
# 每个IP每周期允许的请求数(注意Docker镜像会有多个层,会消耗多个次数)
requestLimit = 500
# 限流周期(小时)
periodHours = 3.0

[security]
# IP白名单,支持单个IP或IP段
# 白名单中的IP不受限流限制
whiteList = [
    "127.0.0.1",
    "172.17.0.0/16",
    "192.168.1.0/24"
]

# IP黑名单,支持单个IP或IP段
# 黑名单中的IP将被直接拒绝访问
blackList = [
    "192.168.100.1",
    "192.168.100.0/24"
]

[access]
# 代理服务白名单(支持GitHub仓库和Docker镜像,支持通配符)
# 只允许访问白名单中的仓库/镜像,为空时不限制
whiteList = []

# 代理服务黑名单(支持GitHub仓库和Docker镜像,支持通配符)
# 禁止访问黑名单中的仓库/镜像
blackList = [
    "baduser/malicious-repo",
    "*/malicious-repo",
    "baduser/*"
]

# 代理配置,支持有用户名/密码认证和无认证模式
# 无认证: socks5://127.0.0.1:1080
# 有认证: socks5://username:password@127.0.0.1:1080
# 留空不使用代理
proxy = "" 

[download]
# 批量下载离线镜像数量限制
maxImages = 10

# Registry映射配置,支持多种镜像仓库上游
[registries]

# GitHub Container Registry
[registries."ghcr.io"]
upstream = "ghcr.io"
authHost = "ghcr.io/token" 
authType = "github"
enabled = true

# Google Container Registry
[registries."gcr.io"]
upstream = "gcr.io"
authHost = "gcr.io/v2/token"
authType = "google"
enabled = true

# Quay.io Container Registry
[registries."quay.io"]
upstream = "quay.io"
authHost = "quay.io/v2/auth"
authType = "quay"
enabled = true

# Kubernetes Container Registry
[registries."registry.k8s.io"]
upstream = "registry.k8s.io"
authHost = "registry.k8s.io"
authType = "anonymous"
enabled = true

[tokenCache]
# 是否启用缓存(同时控制Token和Manifest缓存)显著提升性能
enabled = true
# 默认缓存时间(分钟)
defaultTTL = "20m"

容器内的配置文件位于 /root/config.toml