Files
record-app-next/deploy.sh

46 lines
1.0 KiB
Bash
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.

#!/bin/bash
set -e
# 项目目录名
APP_DIR="record-app"
IMAGE_NAME="recorder-app"
CONTAINER_NAME="recorder-app"
PORT=25190
# 1. 检查 Docker
if ! command -v docker &> /dev/null; then
echo "Docker 未安装,正在安装..."
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
fi
# 2. 检查 Docker Compose可选
if ! command -v docker-compose &> /dev/null; then
echo "Docker Compose 未安装,正在安装..."
sudo apt install -y docker-compose
fi
# 3. 构建镜像
echo "正在构建 Docker 镜像..."
cd $APP_DIR
docker build -t $IMAGE_NAME .
# 4. 停止并删除旧容器
if docker ps -a | grep -q $CONTAINER_NAME; then
echo "停止并删除旧容器..."
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
fi
# 5. 启动新容器
echo "启动新容器..."
docker run -d \
--name $CONTAINER_NAME \
--restart always \
-p $PORT:3000 \
--env-file .env.production \
$IMAGE_NAME
echo "部署完成!请访问 http://<你的服务器IP或域名>:$PORT"