From 254097e026ea830a354dc21cc55294bc2114030a Mon Sep 17 00:00:00 2001 From: hyh Date: Wed, 26 Nov 2025 11:52:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=91=E5=B8=83sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modify.md | 24 +++++++++++++++++++++--- site/deploy-https.sh | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/modify.md b/modify.md index d77a51db..a2232349 100644 --- a/modify.md +++ b/modify.md @@ -19,12 +19,17 @@ - 尝试删除 Docker 网络 - 如果网络仍在使用中则跳过删除 -3. **服务启动**: +3. **镜像清理**: + - 清理未使用的镜像(dangling images) + - 清理构建缓存 + - 确保每次都是全新构建 + +4. **服务启动**: - 使用 docker-compose 启动服务 - - 自动构建镜像(`--build`) + - 构建时使用 `--no-cache` 选项,不使用缓存 - 后台运行(`-d`) -4. **状态检查**: +5. **状态检查**: - 等待容器启动 - 显示容器运行状态 @@ -55,6 +60,19 @@ 变更原因:用户需要在 CentOS 环境中快速部署 HTTPS 版本,需要自动清除之前的容器并重新部署,避免手动操作步骤繁琐。 +**后续修复**: +- **修复 docker-compose 命令兼容性问题**:脚本现在会自动检测并使用正确的 Docker Compose 命令 + - 优先尝试使用 `docker compose`(Docker CLI 插件,新版本) + - 如果不存在,则使用 `docker-compose`(独立命令,旧版本) + - 如果两者都不存在,脚本会报错并退出 + - 修复了 "docker-compose: command not found" 错误 + +- **添加 Docker 镜像和构建缓存清理功能**: + - 在部署前自动清理未使用的镜像(`docker image prune -f`) + - 清理构建缓存(`docker builder prune -f`) + - 构建时使用 `--no-cache` 选项,确保不使用缓存的镜像层 + - 解决因缓存导致的构建问题,确保每次部署都是全新构建 + ## 2025-01-XX - 修复 Next.js 配置警告 ### 修复内容 diff --git a/site/deploy-https.sh b/site/deploy-https.sh index 26ce70e6..fc4e8daf 100644 --- a/site/deploy-https.sh +++ b/site/deploy-https.sh @@ -13,6 +13,19 @@ echo "==========================================" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" +# Detect docker compose command (new version: "docker compose" or old version: "docker-compose") +if docker compose version >/dev/null 2>&1; then + DOCKER_COMPOSE="docker compose" +elif docker-compose version >/dev/null 2>&1; then + DOCKER_COMPOSE="docker-compose" +else + echo "Error: Neither 'docker compose' nor 'docker-compose' command found" + echo "Please install Docker Compose" + exit 1 +fi + +echo "Using: $DOCKER_COMPOSE" + # Define container names MARKETING_CONTAINER="marketing-site-https" NGINX_CONTAINER="nginx-https" @@ -54,14 +67,28 @@ else fi echo "" -echo "Step 3: Starting services with docker-compose..." +echo "Step 3: Cleaning up Docker images and build cache..." +echo "----------------------------------------" + +# Remove dangling images (untagged images) +echo "Removing dangling images..." +docker image prune -f || true + +# Remove build cache to ensure fresh build +echo "Removing build cache..." +docker builder prune -f || true + +echo "" +echo "Step 4: Starting services with docker-compose (no cache)..." echo "----------------------------------------" # Start services with docker-compose (will automatically create network and volumes) -docker-compose -f docker-compose-https.yml up -d --build +# Use --no-cache to ensure fresh build without using cached layers +$DOCKER_COMPOSE -f docker-compose-https.yml build --no-cache +$DOCKER_COMPOSE -f docker-compose-https.yml up -d echo "" -echo "Step 4: Checking container status..." +echo "Step 5: Checking container status..." echo "----------------------------------------" # Wait a few seconds for containers to start @@ -76,9 +103,9 @@ echo "Deployment completed!" echo "==========================================" echo "" echo "View logs command:" -echo " docker-compose -f docker-compose-https.yml logs -f" +echo " $DOCKER_COMPOSE -f docker-compose-https.yml logs -f" echo "" echo "Stop services command:" -echo " docker-compose -f docker-compose-https.yml down" +echo " $DOCKER_COMPOSE -f docker-compose-https.yml down" echo ""