root@cpy-120:/data/files/docker/net-proxy# cat docker-compose.yml
services:
net-proxy:
image: hub-dev.rockontrol.com/proxy/net-proxy:latest
container_name: net-proxy
restart: unless-stopped
ports:
- "5000:5000"
#- "5001:28080"
#- "28081:28081"
# 如启用 custom 分类监听(示例为 28082),请按需放开:
# - "28082:28082"
volumes:
- ./config.yaml:/etc/net-proxy/config.yaml:ro
- ./cache/:/tmp/net-proxy-cache/
command: ["-config", "/etc/net-proxy/config.yaml"]
root@cpy-120:/data/files/docker/net-proxy# cat config.yaml
# =========================
# Net-Proxy 示例配置(中文注释版)
# =========================
server:
# 主服务监听地址(统一入口端口)
# 默认同时承载:
# - GitHub URL 透传代理(/https://...)
# - Docker Registry 代理(/v2/...)
listen: "0.0.0.0:5000"
# 是否在主端口启用 GitHub 代理(默认 true)
enable_github: true
# 是否在主端口启用 Docker 代理(默认 true)
enable_docker: true
# 单次请求读取超时
read_timeout: "600s"
# 单次请求写入超时(0s 表示不限制)
write_timeout: "0s"
# Keep-Alive 空闲连接超时
idle_timeout: "300s"
# HTTP 请求头最大字节数(默认 1MB)
max_header_bytes: 1048576
proxy:
# GitHub 代理时是否由服务端跟随 3xx 重定向
follow_redirects: true
# 最大重定向次数(仅 follow_redirects=true 时生效)
max_redirects: 5
# 请求失败后的重试次数(单上游内部重试)
retry_times: 2
# 每次重试之间的等待时间
retry_backoff: "300ms"
# 是否允许直连私网 IP(生产建议 false)
allow_private_ip: false
# URL 透传模式允许访问的目标域名白名单
# 说明:请求路径形如 /https://目标域名/...
allowed_target_domains:
- github.com
- raw.githubusercontent.com
- codeload.github.com
- objects.githubusercontent.com
- release-assets.githubusercontent.com
- registry-1.docker.io
- auth.docker.io
- ghcr.io
# 全局出站代理(同时用于 HTTP/HTTPS 请求,可选)
# 支持 host:port 或 http://host:port
http_proxy: ""
# 全局 SOCKS5 出站代理(可选)
# 支持 host:port 或 socks5://user:pass@host:port
socks5_proxy: ""
cache:
github_download:
# 是否启用 GitHub 下载磁盘缓存(按“目标 URL 全量”作为缓存键)
# 说明:同名文件只要 URL 中版本路径或查询参数不同,就会分开缓存,不会互相覆盖
enabled: true
# 缓存目录
dir: "/tmp/net-proxy-cache/github-download"
# 总缓存容量上限
max_size: "10GB"
# 单个缓存条目最大大小(超出则不落盘缓存)
max_entry_size: "2GB"
# 缓存过期时间(TTL)
# - >0: 超过该时间未访问则视为过期并清理
# - 0s: 不按 TTL 过期,仅受 max_size 容量限制
ttl: "0s"
# 后台清理周期(负责过期清理和容量回收)
cleanup_interval: "5m"
docker_blob:
# 是否启用 Docker Blob 磁盘缓存(仅缓存 /v2/.../blobs/sha256:* 的完整 GET 响应)
enabled: true
# 缓存目录
dir: "/tmp/net-proxy-cache/docker-blob"
# 总缓存容量上限(支持 B/KB/MB/GB/TB 或 KiB/MiB/GiB/TiB)
# 超出后按最近最少使用(基于文件访问时间)优先淘汰旧条目
max_size: "200GB"
# 单个缓存条目最大大小(超出则不落盘缓存)
max_entry_size: "2GB"
# 缓存过期时间(TTL)
# - >0: 超过该时间未访问则视为过期并清理
# - 0s: 不按 TTL 过期,仅受 max_size 容量限制
ttl: "0s"
# 后台清理周期(负责过期清理和容量回收)
cleanup_interval: "60m"
routing:
# GitHub 上游路由策略(当前支持 priority)
github_strategy: "priority"
# Docker 上游路由策略(当前支持 priority)
docker_strategy: "priority"
# GitHub 规则路由(按请求目标 host/path 选择上游)
# 按顺序匹配第一条命中规则
github_rules:
# raw 文件优先走 ghfast 与 jsdelivr,失败再回退 direct
- name: "raw-files"
host: "raw.githubusercontent.com"
upstreams:
- "ghfast-prefix"
- "jsdelivr-raw"
- "gh-direct"
# false: 规则上游优先,其它上游可继续作为兜底
exclusive: false
# GitHub Release 下载优先走 ghfast,再回退 direct
- name: "github-releases"
host: "github.com"
path_regex: "^/.+/.+/releases/download/"
upstreams:
- "ghfast-prefix"
- "gh-direct"
exclusive: false
# =========================
# GitHub 模块
# =========================
github:
listeners:
# 可选:独立 GitHub 业务端口
# 适合将 GH 与 Docker 完全分开暴露(例如配合 Nginx 域名分流)
- name: "github-download"
listen: "0.0.0.0:28070"
enabled: false
# =========================
# Docker 模块
# =========================
docker:
# 单端口域名路由(可选)
# 场景:只开放 server.listen 一个端口,通过 Host 头映射不同 Docker 分类(推荐读写分离)
# 例如:
# - hub-mirror.local.com -> official-read
# - hub-push.local.com -> official-write
# - ghcr-mirror.local.com -> ghcr-read
# - ghcr-push.local.com -> ghcr-write
host_routing:
enabled: true
rules:
- host: "hub-mirror.local.com"
category: "official-read"
- host: "hub-push.local.com"
category: "official-write"
- host: "ghcr-mirror.local.com"
category: "ghcr-read"
- host: "ghcr-push.local.com"
category: "ghcr-write"
listeners:
# 官方 Pull 业务端口(镜像站优先)
- name: "docker-official-read"
listen: "0.0.0.0:55000"
category: "official-read"
enabled: true
# GHCR Pull 业务端口
- name: "docker-ghcr-read"
listen: "0.0.0.0:55001"
category: "ghcr-read"
enabled: true
# 官方 Push 业务端口(仅官方可写上游)
- name: "docker-official-write"
listen: "0.0.0.0:50000"
category: "official-write"
enabled: true
# GHCR Push 业务端口
- name: "docker-ghcr-write"
listen: "0.0.0.0:50001"
category: "ghcr-write"
enabled: true
# 第三方自定义仓库业务端口(示例默认关闭)
- name: "docker-custom"
listen: "0.0.0.0:55002"
category: "custom"
enabled: false
upstreams:
# =========================
# GitHub 上游
# =========================
github:
# 直连上游(保持原始目标 URL,不做改写)
- name: "gh-direct"
mode: "direct"
# 注意:direct 模式下 base_url 不参与实际转发,仅用于健康检查兜底
base_url: "https://github.com"
priority: 80
healthcheck_url: "https://github.com/"
enabled: true
# 可选:按上游覆盖出站代理(不填则继承 proxy.* 全局设置)
# 说明:http_proxy 同时用于 HTTP/HTTPS
http_proxy: ""
socks5_proxy: ""
# 前缀镜像上游(示例:ghfast.top)
# 原始请求:https://raw.githubusercontent.com/a/b/c
# 转发目标:https://ghfast.top/https://raw.githubusercontent.com/a/b/c
- name: "ghfast-prefix"
mode: "url_prefix"
base_url: "https://ghfast.top"
priority: 100
healthcheck_url: "https://ghfast.top/https://raw.githubusercontent.com/DustinWin/ruleset_geodata/master/rule_templates/DustinWin_Full.ini"
enabled: true
http_proxy: ""
socks5_proxy: ""
# raw.githubusercontent.com -> jsDelivr 映射上游
# 原始请求:https://raw.githubusercontent.com/{owner}/{repo}/{ref}/{file}
# 转发目标:https://cdn.jsdelivr.net/gh/{owner}/{repo}@{ref}/{file}
- name: "jsdelivr-raw"
mode: "raw_to_jsdelivr"
base_url: "https://cdn.jsdelivr.net"
priority: 90
healthcheck_url: "https://cdn.jsdelivr.net/gh/DustinWin/ruleset_geodata@master/rule_templates/DustinWin_Full.ini"
enabled: true
http_proxy: ""
socks5_proxy: ""
# =========================
# Docker 上游
# =========================
docker:
# 官方 Docker Hub(Push 专用:只放可写官方)
- name: "dockerhub-main-write"
category: "official-write"
registry_host: "registry-1.docker.io"
auth_host: "auth.docker.io"
token_path: "/token"
scheme: "https"
priority: 100
enabled: true
# 可选:给上游配置固定账号密码(客户端未带 Authorization 时会自动注入)
# 也可通过环境变量覆盖(优先级更高):
# - NET_PROXY_DOCKER_DOCKERHUB_MAIN_WRITE_USERNAME
# - NET_PROXY_DOCKER_DOCKERHUB_MAIN_WRITE_PASSWORD
http_proxy: ""
socks5_proxy: "192.168.31.120:10081"
# 官方 Docker Hub(Pull 兜底)
- name: "dockerhub-main-read"
category: "official-read"
registry_host: "registry-1.docker.io"
auth_host: "auth.docker.io"
token_path: "/token"
scheme: "https"
priority: 100
enabled: true
http_proxy: ""
socks5_proxy: "192.168.31.120:10081"
# Docker Hub 镜像站(Pull 优先)
- name: "dockerhub-mirror-1-read"
category: "official-read"
registry_host: "docker.1ms.run"
# docker.1ms.run 当前返回的挑战 realm 为 /openapi/v1/auth/token
auth_host: "docker.1ms.run"
token_path: "/openapi/v1/auth/token"
scheme: "https"
priority: 90
enabled: true
username: ""
password: ""
http_proxy: ""
socks5_proxy: ""
# GHCR(Pull)
- name: "ghcr-main-read"
category: "ghcr-read"
registry_host: "ghcr.io"
auth_host: "ghcr.io"
token_path: "/token"
scheme: "https"
priority: 100
enabled: true
username: ""
password: ""
http_proxy: ""
socks5_proxy: "192.168.31.120:10081"
# GHCR(Push)
- name: "ghcr-main-write"
category: "ghcr-write"
registry_host: "ghcr.io"
auth_host: "ghcr.io"
token_path: "/token"
scheme: "https"
priority: 100
enabled: true
username: ""
password: ""
http_proxy: ""
socks5_proxy: "192.168.31.120:10081"
# 第三方自定义仓库(示例)
- name: "custom-registry-1"
category: "custom"
registry_host: "registry.example.com"
auth_host: "auth.example.com"
token_path: "/token"
scheme: "https"
priority: 100
enabled: false
username: ""
password: ""
http_proxy: ""
socks5_proxy: ""
healthcheck:
# 健康检查执行周期
interval: "10s"
# 单次健康检查超时
timeout: "2s"
# 说明:健康检查会跟随当前上游代理环境
# - GitHub:优先 upstreams.github[].http_proxy/socks5_proxy,未配置则继承 proxy.*
# - Docker:优先 upstreams.docker[].http_proxy/socks5_proxy,未配置则继承 proxy.*
# 连续失败达到阈值后,标记上游为不健康
unhealthy_threshold: 3
# 连续成功达到阈值后,标记上游恢复健康
healthy_threshold: 2
logging:
# 日志级别:debug/info/warn/error
level: "debug"
# 日志输出格式(当前推荐 json)
format: "json"
metrics:
# 是否启用 Prometheus 指标接口
enabled: true
# 指标暴露路径
path: "/metrics"
# 当前缓存相关指标(自动输出到 /metrics):
# - cache_hits_total{service,cache,result}
# - cache_hit_ratio{service,cache}
# - cache_bytes_total{service,cache,op}
# - cache_evictions_total{service,cache,reason}
root@cpy-120:/data/files/docker/net-proxy#
Content type
Image
Digest
sha256:c8c70196f…
Size
6.2 MB
Last updated
3 months ago
docker pull corray/net-proxy