Files
wechatAiclaw/run-docker.sh
2026-03-11 09:44:17 +08:00

40 lines
1.1 KiB
Bash
Executable File
Raw 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.
#!/usr/bin/env bash
set -e
IMAGE_NAME="wechat-admin-backend"
CONTAINER_NAME="wechat-admin-backend"
PORT="${PORT:-3000}"
# 数据目录挂载到宿主机防止容器删除后丢失SQLite 库 wechat.db 及表数据)
HOST_DATA_DIR="${HOST_DATA_DIR:-$(pwd)/data}"
echo "Building Docker image: ${IMAGE_NAME}..."
docker build -t "${IMAGE_NAME}" .
echo "Stopping and removing existing container (if any)..."
if [ "$(docker ps -aq -f name=${CONTAINER_NAME})" ]; then
docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || true
fi
mkdir -p "${HOST_DATA_DIR}"
echo "Data dir (host): ${HOST_DATA_DIR} -> container /app/backend/data"
ENV_FILE=".env"
if [ ! -f "${ENV_FILE}" ]; then
echo "Env file ${ENV_FILE} not found, copying from .env.example ..."
cp .env.example "${ENV_FILE}"
fi
echo "Running container ${CONTAINER_NAME} on port ${PORT}..."
docker run -d \
--name "${CONTAINER_NAME}" \
--env-file "${ENV_FILE}" \
-p "${PORT}:3000" \
-p "8000:8000" \
-v "${HOST_DATA_DIR}:/app/backend/data" \
"${IMAGE_NAME}"
echo "Container started. Data persisted on host: ${HOST_DATA_DIR}"
echo "Health check: curl http://localhost:${PORT}/health"