Files
dysync/docs/403错误解决方案.md
yuming ad97fd3da5 整理仓库:扩展 gitignore、归档文档、清理冗余 Dockerfile
- .gitignore 新增忽略 .idea/、videos/、*.tar.gz、*.csproj.user、db 运行时文件
- 根目录 15 个中文运维 md 归档到 docs/
- 删除无部署脚本引用的 Dockerfile 与 Dockerfile-arm(保留 Dockerfile.prod)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 21:28:41 +08:00

179 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Docker 构建 403 Forbidden 错误解决方案
## 当前问题
**错误信息**:
```
403 Forbidden from https://dockerhub.azk8s.cn/v2/library/node/manifests/18-alpine
```
**原因**:
- 某些镜像加速器返回 403,可能是需要认证或已限制访问
- 网络环境可能有限制
## 🚀 解决方案(按推荐顺序)
### 方案一:移除有问题的镜像源,只保留阿里云(最简单)
**已更新配置**:只保留阿里云镜像源
**操作步骤**:
1. **重启 Docker Desktop**(必须)
- 完全退出 Docker Desktop
- 重新启动
2. **尝试构建**
```bash
cd /Users/gaotu/WebstormProjects/dysync.net
docker build -f Dockerfile.prod -t dysync.net:latest .
```
### 方案二:手动拉取镜像(推荐)
如果构建时拉取失败,可以尝试手动拉取:
```bash
# 尝试手动拉取 node 镜像(会使用配置的镜像源)
docker pull node:18-alpine
# 如果成功,再拉取其他镜像
docker pull mcr.microsoft.com/dotnet/sdk:6.0
docker pull mcr.microsoft.com/dotnet/aspnet:6.0
# 然后再构建(此时会使用本地已拉取的镜像)
docker build -f Dockerfile.prod -t dysync.net:latest .
```
### 方案三:使用阿里云专属加速器(最稳定)
如果你有阿里云账号:
1. **登录阿里云容器镜像服务**
- 访问:https://cr.console.aliyun.com/
- 登录你的阿里云账号
2. **获取专属加速地址**
- 进入 "镜像加速器" 页面
- 复制你的专属加速地址(格式:`https://xxxxx.mirror.aliyuncs.com`)
3. **更新 Docker 配置**
```bash
cat > ~/.docker/daemon.json << EOF
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false,
"registry-mirrors": [
"https://你的专属地址.mirror.aliyuncs.com"
]
}
EOF
```
4. **重启 Docker Desktop**
5. **重新构建**
### 方案四:配置 Docker Desktop 代理(如果有代理)
如果你有可用的 HTTP/HTTPS 代理:
1. **打开 Docker Desktop 设置**
- 点击状态栏 Docker 图标 → Settings
2. **配置代理**
- 进入 "Resources" → "Proxies"
- 启用 "Manual proxy configuration"
- 填写代理地址和端口(例如:`127.0.0.1:7890`)
- 点击 "Apply & Restart"
3. **移除镜像加速器配置**(使用代理时不需要)
```bash
cat > ~/.docker/daemon.json << EOF
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false
}
EOF
```
4. **重启 Docker Desktop**
5. **重新构建**
### 方案五:使用 VPN 或科学上网工具
如果你有 VPN 或科学上网工具:
1. **启动 VPN/科学上网工具**
2. **配置系统代理**(如果工具支持)
3. **在 Docker Desktop 中配置代理**(参考方案四)
4. **重新构建**
### 方案六:跳过前端构建,只构建后端(临时方案)
如果前端构建一直失败,可以临时跳过前端构建:
1. **修改 Dockerfile.prod**,注释掉前端构建部分
2. **只构建后端**
3. **前端可以单独部署或后续再处理**
**注意**:这不是推荐方案,因为前端需要包含在镜像中。
### 方案七:在飞牛 NAS 上直接构建
如果本地构建一直失败,可以考虑:
1. **将项目文件上传到飞牛 NAS**
2. **通过 SSH 连接到飞牛 NAS**
3. **在 NAS 上直接构建**(NAS 的网络环境可能不同)
## 🔍 诊断命令
运行以下命令帮助诊断:
```bash
# 1. 检查当前镜像源配置
docker info | grep -A 10 "Registry Mirrors"
# 2. 测试拉取镜像
docker pull node:18-alpine
# 3. 查看 Docker 日志(如果有错误)
docker system events
# 4. 检查网络连接
curl -I https://registry.cn-hangzhou.aliyuncs.com/v2/
```
## 📝 当前配置
已更新 `~/.docker/daemon.json`,只保留阿里云镜像源:
```json
{
"registry-mirrors": [
"https://registry.cn-hangzhou.aliyuncs.com"
]
}
```
**重要**:需要重启 Docker Desktop 才能生效!
## 🎯 推荐操作顺序
1. ✅ **先试方案一**:重启 Docker Desktop,使用更新后的配置
2. 如果还不行,**试方案二**:手动拉取镜像
3. 如果还不行,**试方案三**:配置阿里云专属加速器
4. 如果还不行,**试方案四**:配置代理(如果有)
5. 最后考虑**方案七**:在 NAS 上构建