fix: 修复生产环境

This commit is contained in:
丹尼尔
2026-03-15 17:59:56 +08:00
parent 0e9bdf0052
commit 31cac56fad
5 changed files with 85 additions and 9 deletions

View File

@@ -5,7 +5,6 @@
# -p, --port PORT 前端宿主机端口,默认 3000
# -b, --backend-port PORT 后端 API 宿主机端口,默认 8000容器内固定 8000
# -d, --data-dir DIR 数据目录挂载,默认 ./data
cp .env.prod.example .env.prod
set -e
IMAGE_NAME="wechat-admin-backend"
@@ -62,11 +61,26 @@ echo "Running container ${CONTAINER_NAME} (frontend :${PORT}, backend :${BACKEND
docker run -d \
--name "${CONTAINER_NAME}" \
--env-file "${ENV_FILE}" \
-e "HOST=0.0.0.0" \
-e "PORT=3000" \
-e "BACKEND_PORT=8000" \
-p "${PORT}:3000" \
-p "${BACKEND_PORT}:8000" \
-v "${HOST_DATA_DIR}:/app/backend/data" \
"${IMAGE_NAME}"
echo "Waiting for frontend to be ready..."
for i in 1 2 3 4 5 6 7 8 9 10; do
if curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:${PORT}/" 2>/dev/null | grep -q 200; then
echo "Frontend ready."
break
fi
if [ "$i" -eq 10 ]; then
echo "WARN: Frontend did not respond with 200 after 10s. Check: docker logs ${CONTAINER_NAME}"
fi
sleep 1
done
echo "Container started. Data persisted on host: ${HOST_DATA_DIR}"
echo "Frontend: http://localhost:${PORT} | Backend API: http://localhost:${BACKEND_PORT} | Health: curl http://localhost:${PORT}/health"