Files
schoolNews/docker/Dockerfile.web
2025-11-24 14:33:02 +08:00

54 lines
1.4 KiB
Docker
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.

# ====================================
# 前端服务镜像 - School News Web
# 使用Node运行Vite预览服务器
# 注意dist目录需要在主机中先构建好
# ====================================
FROM node:20-alpine
# 设置环境变量
ENV TZ=Asia/Shanghai \
NODE_ENV=production
# 安装基础工具
RUN apk add --no-cache tzdata bash curl && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# 创建应用目录
WORKDIR /app
# 创建必要目录
RUN mkdir -p /app/dist /app/config /app/logs
# 复制package.json和package-lock.json
COPY schoolNewsWeb/package*.json ./
# 安装生产依赖包括vite用于preview
RUN npm ci --only=production && \
npm install -g vite
# 从主机复制已构建的dist目录
COPY schoolNewsWeb/dist/ /app/dist/
# 复制配置文件模板(可整个替换)
COPY schoolNewsWeb/public/app-config.js /app/config/app-config.js.template
# 确保dist中有默认配置文件
RUN if [ ! -f /app/dist/app-config.js ]; then \
cp /app/config/app-config.js.template /app/dist/app-config.js; \
fi
# 复制启动脚本
COPY schoolNewsWeb/docker/start.sh /app/start.sh
RUN chmod +x /app/start.sh
# 暴露端口Vite preview默认4173
EXPOSE 4173
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \
CMD curl -f http://localhost:4173/ || exit 1
# 启动应用
CMD ["/app/start.sh"]