This commit is contained in:
Olia Lisa 2026-01-14 17:13:35 +08:00
parent 16a80faea4
commit 584d6ba143

View File

@ -3,26 +3,14 @@
run(){ run(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local docker_compose_file="$script_dir/../docker-compose.yml" local docker_compose_file="$script_dir/../docker-compose.yml"
local running_count=$(docker-compose -f "$docker_compose_file" ps -q --filter "status=running" | wc -l) local running_count=$(docker-compose -f "$docker_compose_file" ps -q --filter "status=running" | wc -l)
# 如果容器已启动
if [ "$running_count" -gt 0 ]; then if [ "$running_count" -gt 0 ]; then
read -p "容器已启动,是否重启容器?(y/n): " choice docker-compose -f "$docker_compose_file" down # 关闭容器
case "$choice" in
Y|y)
echo "正在重启容器..."
docker-compose -f "$docker_compose_file" down
docker-compose -f "$docker_compose_file" up -d
return
;;
*)
echo "已取消操作"
exit 0
;;
esac
fi fi
docker-compose -f "$docker_compose_file" up -d docker-compose -f "$docker_compose_file" up -d # 启动容器
} }