Files
Novault-Frontend-web/Dockerfile
2026-01-25 20:12:33 +08:00

57 lines
1.3 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.
# 多阶段构建 - 前端 Dockerfile
# 阶段 1: 构建阶段
FROM node:20-alpine AS builder
# 设置工作目录
WORKDIR /app
# 配置 npm 国内镜像
RUN npm config set registry https://registry.npmmirror.com
# 复制 package 文件
COPY package*.json ./
# 安装所有依赖(包括 devDependencies
RUN npm ci
# 复制源代码
COPY . .
# 构建生产版本
RUN npm run build
# 阶段 2: 运行阶段
FROM nginx:alpine
# 配置 Alpine 国内镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装 tzdata 用于时区设置
RUN apk --no-cache add tzdata
# 设置时区为上海
ENV TZ=Asia/Shanghai
# 删除默认的 nginx 配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/
# 从构建阶段复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 创建非 root 用户nginx 已经有了,但我们确保权限正确)
RUN chown -R nginx:nginx /usr/share/nginx/html && \
chmod -R 755 /usr/share/nginx/html
# 暴露端口
EXPOSE 2613
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:2613/ || exit 1
# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]