-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
60 lines (47 loc) · 1.44 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Stage 1: 依赖安装和应用构建
FROM node:22-alpine AS builder
WORKDIR /app
RUN npm config set registry https://registry.npmmirror.com
RUN apk add --no-cache libc6-compat
ENV NEXT_SWC=0 \
NEXT_TELEMETRY_DISABLED=1 \
PRISMA_HIDE_UPDATE_MESSAGE=1
COPY package*.json ./
RUN npm ci --legacy-peer-deps
COPY . .
RUN npx prisma generate
RUN npm run build
# Stage 2: 生产环境运行
FROM node:22-alpine AS runner
WORKDIR /app
# 基础环境变量
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PRISMA_HIDE_UPDATE_MESSAGE=1
# 创建非root用户
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# 从builder阶段复制必要文件
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
# 创建data目录
RUN mkdir -p /app/data
# 安装全局 Prisma CLI 和必要工具
RUN npm config set registry https://registry.npmmirror.com
RUN npm install prisma@latest -g
RUN npm install @prisma/client -g
RUN apk add --no-cache su-exec sqlite
# 设置data目录作为卷
VOLUME /app/data
# 复制启动脚本
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
# 暴露端口
EXPOSE 3000
# 使用root用户启动入口点脚本
USER root
CMD ["/app/entrypoint.sh"]