主题
Docker Registry 私有仓库部署
概述
在 117.50.188.237 上通过 Docker 容器部署私有镜像仓库,地址为 117.50.188.237:30000。 所有 k3s 集群使用的镜像已推送到该仓库,并配置为 k3s containerd 的镜像加速源。
1. 拉取 Registry 镜像
bash
# 从华为云 SWR 拉取
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/registry:latest2. 启动 Registry 容器
bash
sudo mkdir -p /opt/registry
docker run -d \
--name docker-registry \
--restart=always \
-p 30000:5000 \
-v /opt/registry:/var/lib/registry \
-e REGISTRY_STORAGE_DELETE_ENABLED=true \
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/registry:latest- 端口: 30000(HTTP,无需 TLS)
- 持久化:
/opt/registry→/var/lib/registry - 自动重启:
--restart=always
3. 推送镜像到仓库
由于 ctr images push 无法通过公网 IP 回环(NAT 限制),需使用 localhost:30000 推送:
bash
REGISTRY="localhost:30000"
CTR="k3s ctr"
# 对每个镜像执行 tag + push
# 示例: docker.io/vllm/vllm-openai:v0.8.4
IMG="docker.io/vllm/vllm-openai:v0.8.4"
$CTR images tag "$IMG" "${REGISTRY}/${IMG}"
$CTR images push --plain-http "${REGISTRY}/${IMG}"
# 同时推送无前缀版本(供 k3s mirror 使用)
SHORT="${IMG#docker.io/}"
$CTR images tag "$IMG" "${REGISTRY}/${SHORT}"
$CTR images push --plain-http "${REGISTRY}/${SHORT}"已推送的镜像列表
| 原始镜像 | 仓库路径(带前缀) | 仓库路径(无前缀,mirror 用) |
|---|---|---|
| docker.io/vllm/vllm-openai:v0.8.4 | docker.io/vllm/vllm-openai:v0.8.4 | vllm/vllm-openai:v0.8.4 |
| docker.io/projecthami/hami:v2.9.0 | docker.io/projecthami/hami:v2.9.0 | projecthami/hami:v2.9.0 |
| docker.io/rancher/klipper-lb:v0.4.17 | docker.io/rancher/klipper-lb:v0.4.17 | rancher/klipper-lb:v0.4.17 |
| docker.io/rancher/klipper-helm:v0.13.3-build20260727 | 同上模式 | rancher/klipper-helm:... |
| docker.io/rancher/local-path-provisioner:v0.0.36 | 同上模式 | rancher/local-path-provisioner:... |
| docker.io/rancher/mirrored-coredns-coredns:1.14.6 | 同上模式 | rancher/mirrored-coredns-coredns:... |
| docker.io/rancher/mirrored-library-traefik:3.7.8 | 同上模式 | rancher/mirrored-library-traefik:... |
| docker.io/rancher/mirrored-metrics-server:v0.9.0 | 同上模式 | rancher/mirrored-metrics-server:... |
| docker.io/rancher/mirrored-pause:3.10.2 | 同上模式 | rancher/mirrored-pause:... |
| docker.io/rancher/mirrored-pause:3.6 | 同上模式 | rancher/mirrored-pause:... |
| docker.io/library/registry:latest | docker.io/library/registry:latest | library/registry:latest |
| docker.io/jettech/kube-webhook-certgen:v1.5.2 | 同上模式 | jettech/kube-webhook-certgen:... |
| docker.io/liangjw/kube-webhook-certgen:v1.1.1 | 同上模式 | liangjw/kube-webhook-certgen:... |
| ghcr.io/open-webui/open-webui:main | ghcr.io/open-webui/open-webui:main | open-webui/open-webui:main |
| registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.36.3 | 原路径 | google_containers/kube-scheduler:... |
总存储: ~11GB(layers 去重后)
4. 配置 k3s 镜像加速
编辑 /etc/rancher/k3s/registries.yaml:
yaml
mirrors:
docker.io:
endpoint:
- "http://117.50.188.237:30000"
- "https://registry.cn-hangzhou.aliyuncs.com"
gcr.io:
endpoint:
- "http://117.50.188.237:30000"
- "https://registry.cn-hangzhou.aliyuncs.com"
ghcr.io:
endpoint:
- "http://117.50.188.237:30000"
- "https://registry.cn-hangzhou.aliyuncs.com"
quay.io:
endpoint:
- "http://117.50.188.237:30000"
- "https://registry.cn-hangzhou.aliyuncs.com"
registry.cn-hangzhou.aliyuncs.com:
endpoint:
- "http://117.50.188.237:30000"
"117.50.188.237:30000":
endpoint:
- "http://117.50.188.237:30000"bash
sudo systemctl restart k3s工作原理
- Mirror 模式:k3s 拉取
docker.io/vllm/vllm-openai:v0.8.4时,先尝试http://117.50.188.237:30000/v2/vllm/vllm-openai/manifests/v0.8.4(无前缀路径),失败才回退到阿里云镜像站 - 直接引用:也可在 YAML 中使用
image: 117.50.188.237:30000/docker.io/vllm/vllm-openai:v0.8.4
5. 验证
bash
# 检查 Registry 运行状态
docker ps | grep registry
# 查看仓库中的镜像列表
curl -s http://117.50.188.237:30000/v2/_catalog | python3 -m json.tool
# 查看某个镜像的 tags
curl -s http://117.50.188.237:30000/v2/vllm/vllm-openai/tags/list
# 检查存储占用
du -sh /opt/registry/
# 从本地拉取测试
k3s ctr images pull --plain-http 117.50.188.237:30000/vllm/vllm-openai:v0.8.46. 管理操作
bash
# 停止 Registry
docker stop docker-registry
# 启动 Registry
docker start docker-registry
# 查看日志
docker logs docker-registry
# 备份仓库数据
sudo tar czf /tmp/registry-backup-$(date +%Y%m%d).tar.gz /opt/registry/
# 清理未使用的镜像(需开启 delete 功能)
# 已通过 REGISTRY_STORAGE_DELETE_ENABLED=true 启用