diff --git a/Dockerfile b/Dockerfile index 8cc7d8b..ea458ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# 使用国内镜像源(可选,如果 Docker 加速器无效) +# FROM registry.cn-hangzhou.aliyuncs.com/library/node:18-alpine FROM node:18-alpine WORKDIR /app diff --git a/README.md b/README.md index 010b51d..50e4043 100644 --- a/README.md +++ b/README.md @@ -241,25 +241,82 @@ docker run -d \ #### 🔧 Docker 故障排查 +**查看容器日志** ```bash -# 查看容器日志 docker logs --tail 100 qiniu-bot +``` -# 进入容器调试 +**进入容器调试** +```bash docker exec -it qiniu-bot /bin/sh +``` -# 检查容器健康状态 +**检查容器健康状态** +```bash docker inspect --format='{{.State.Health.Status}}' qiniu-bot +``` -# 查看资源使用 +**查看资源使用** +```bash docker stats qiniu-bot +``` -# 清理未使用的镜像 +**清理未使用的镜像** +```bash docker image prune -a ``` --- +#### 🌏 国内网络问题(镜像拉取超时) + +**问题:** `failed to solve: DeadlineExceeded: node:18-alpine: failed to resolve source metadata` + +**解决方案 1:配置 Docker 镜像加速器** + +```bash +# 配置镜像加速器 +sudo tee /etc/docker/daemon.json <<-'EOF' +{ + "registry-mirrors": [ + "https://docker.mirrors.ustc.edu.cn", + "https://hub-mirror.c.163.com", + "https://mirror.baidubce.com" + ] +} +EOF + +# 重启 Docker +sudo systemctl daemon-reload +sudo systemctl restart docker + +# 验证 +docker info | grep "Registry Mirrors" +``` + +**解决方案 2:使用国内 Node.js 镜像** + +修改 `Dockerfile` 第一行: +```dockerfile +# 使用阿里云镜像 +FROM registry.cn-hangzhou.aliyuncs.com/library/node:18-alpine +``` + +**解决方案 3:手动拉取镜像** + +```bash +# 先手动拉取(使用加速器) +docker pull registry.cn-hangzhou.aliyuncs.com/library/node:18-alpine + +# 打标签 +docker tag registry.cn-hangzhou.aliyuncs.com/library/node:18-alpine node:18-alpine + +# 重新构建 +docker-compose up -d --build +``` + +--- + #### 📋 Docker 部署检查清单 - [ ] `.env` 文件已配置(包含飞书和七牛云密钥)