master
问题诊断: 1. Web UI 使用 host.docker.internal 无法在远程浏览器访问 2. 原安装脚本在某些情况下容器无法启动 3. Docker 响应慢导致脚本超时 解决方案: 1. 使用纯代理模式 (仅 NGINX_PROXY_PASS_URL) 2. 去掉 REGISTRY_URL 避免前端直接访问 3. 创建简化的安装脚本 install-registry-fresh.sh 4. 使用短容器名 (reg-private, reg-ui) 避免冲突 新增文件: - install-registry-fresh.sh - 简化可靠的安装脚本 - test-ui-simple.sh - 逐步诊断测试脚本 修改文件: - install-local-registry-macos.sh - 使用纯代理模式 测试结果: ✓ 所有容器成功启动 (reg-private, reg-cache, reg-ui, reg-cache-ui) ✓ API 访问正常 (localhost:15000, localhost:15001) ✓ UI 代理正常 (localhost:8082, localhost:8083) ✓ 远程访问正常 (http://192.168.1.83:8082) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
本地 Docker Registry 系统
轻量级的本地镜像仓库解决方案,替代 Harbor 用于开发环境。
⚠️ 重要提示
-
macOS 用户:请使用
./install-local-registry-macos.sh并阅读 README-MACOS.md- macOS 使用端口 15000/15001(5000/5001 被系统占用)
- 数据存储在
~/registry/(不需要 sudo)
-
Linux 用户:请使用
./install-local-registry.sh并阅读本文档- Linux 使用端口 5000/5001
- 数据存储在
/opt/registry/ - 支持 containerd + Kubernetes 集成
特性
- 业务私有仓库 (localhost:5000) - 存储和管理业务镜像
- Docker Hub 缓存 (localhost:5001) - 自动缓存公共镜像,加速拉取
- Web UI 管理 - 可视化管理镜像(端口 8082, 8083)
- Kubernetes 集成 - 无缝集成到 k8s 集群
- 轻量快速 - 仅 4 个容器,< 30 秒启动
快速开始
前置要求
- Linux 服务器(Ubuntu/CentOS/Debian)
- Docker 20.10+
- 可选:Kubernetes 1.24+ + containerd 1.6+
一键安装
# 下载并运行安装脚本
chmod +x install-local-registry.sh
./install-local-registry.sh
访问 Web UI
- 业务仓库:
http://<服务器IP>:8082 - 缓存仓库:
http://<服务器IP>:8083
使用示例
推送业务镜像
# 构建镜像
docker build -t localhost:5000/ljwx/myapp:dev .
# 推送到私有仓库
docker push localhost:5000/ljwx/myapp:dev
在 Kubernetes 中使用
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
template:
spec:
containers:
- name: myapp
image: localhost:5000/ljwx/myapp:dev
imagePullPolicy: IfNotPresent
验证缓存功能
# 第一次拉取(会缓存)
sudo crictl pull docker.io/library/nginx:1.27
# 第二次拉取(明显更快)
sudo crictl pull docker.io/library/nginx:1.27
文档
项目结构
.
├── README.md # 本文件
├── DEV-REGISTRY-SETUP.md # 完整文档
├── VERIFICATION-CHECKLIST.md # 验证清单
├── install-local-registry.sh # 一键安装脚本
├── 01-create-directories.sh # 创建目录
├── 02-start-registry-private.sh # 启动业务仓库
├── 03-start-registry-cache.sh # 启动缓存仓库
├── 04-start-registry-ui.sh # 启动 Web UI
├── 05-configure-containerd.sh # 配置 containerd
├── 06-verify-cache.sh # 验证缓存
├── config-private-registry.yml # 业务仓库配置
├── config-cache-registry.yml # 缓存仓库配置
├── containerd-registry-config.toml # containerd 配置片段
└── examples/
├── build-push-example.sh # 构建推送示例
├── deployment-stock-recommender.yaml # k8s Deployment 示例
└── Dockerfile.example # Dockerfile 示例
架构
┌─────────────────────────────────────────────────────────┐
│ Linux 开发服务器 │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ registry- │ │ registry- │ │
│ │ private │ │ cache │ │
│ │ :5000 │ │ :5001 │ │
│ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │
│ ┌──────▼───────┐ ┌──────▼───────┐ │
│ │ Web UI │ │ Web UI │ │
│ │ :8082 │ │ :8083 │ │
│ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ containerd + Kubernetes │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
常见问题
端口被占用怎么办?
修改脚本中的端口映射(例如 -p 15000:5000)
containerd 配置不生效?
# 检查配置
sudo crictl info | grep -A20 registry
# 重启服务
sudo systemctl restart containerd kubelet
如何清理缓存?
docker stop registry-cache
sudo rm -rf /opt/registry/cache/data/*
docker start registry-cache
更多问题请查看 完整文档
生产环境迁移
开发验证完成后,可以迁移到生产环境:
- 推荐使用 Harbor(生产级功能)
- 或继续使用 Registry(需配置 HTTPS + 认证)
详细迁移指南请查看 生产环境迁移章节
支持
如有问题,请查看文档或联系 DevOps 团队。
License
MIT
Languages
Shell
100%