From 7ca85bfe6be93c4b956803d64b5f15fe7c59eb0b Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 23 Jun 2026 15:15:56 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E6=80=A7=20PHP=20=E5=AE=B9=E5=99=A8=E6=89=A7=E8=A1=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd b/cmd index c30d4c5c0..d8b6b7378 100755 --- a/cmd +++ b/cmd @@ -250,6 +250,18 @@ container_exec() { docker exec $TTY_FLAG "$name" /bin/sh -c "$cmd" } +# 使用当前 docker-compose.yml 定义的服务镜像执行一次性容器命令 +container_run() { + local container=$1 + shift 1 + local cmd=$@ + if [ -t 0 ] && [ -t 1 ]; then + $COMPOSE run --rm "$container" /bin/sh -c "$cmd" + else + $COMPOSE run --rm -T "$container" /bin/sh -c "$cmd" + fi +} + # 备份数据库、还原数据库 mysql_snapshot() { if [ "$1" = "backup" ]; then @@ -706,7 +718,7 @@ handle_update() { fi # 更新依赖 - exec_judge "container_exec php 'composer install --optimize-autoloader'" "更新PHP依赖失败" + exec_judge "container_run php 'composer install --optimize-autoloader'" "更新PHP依赖失败" else # 本地更新模式 echo "执行数据库备份..." @@ -714,7 +726,7 @@ handle_update() { fi # 数据库迁移 - exec_judge "container_exec php 'php artisan migrate'" "数据库迁移失败" + exec_judge "container_run php 'php artisan migrate'" "数据库迁移失败" # 停止服务 $COMPOSE stop php nginx &> /dev/null