lty/qy-lty-admin/Dockerfile
2026-03-17 13:17:02 +08:00

52 lines
1.1 KiB
Docker
Raw Permalink 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.

# 构建阶段
FROM node:22.10.0-alpine AS builder
# 设置工作目录
WORKDIR /app
# 设置yarn镜像源为淘宝镜像
RUN yarn config set registry https://registry.npmmirror.com && \
yarn config set disturl https://npmmirror.com/dist --global
# 复制package.json和yarn.lock
COPY package.json yarn.lock* ./
# 安装依赖包括devDependencies用于构建
RUN yarn install --frozen-lockfile
# 复制源代码
COPY . .
# 构建应用
RUN yarn build
# 运行阶段
FROM node:22.10.0-alpine AS runner
# 设置工作目录
WORKDIR /app
# 设置yarn镜像源为淘宝镜像
RUN yarn config set registry https://registry.npmmirror.com && \
yarn config set disturl https://npmmirror.com/dist --global
# 复制package.json和yarn.lock
COPY package.json yarn.lock* ./
# 仅安装生产依赖
RUN yarn install --production --frozen-lockfile
# 设置环境变量
ENV NODE_ENV=production
ENV PATH=/app/node_modules/.bin:$PATH
# 从构建阶段复制构建产物
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.mjs ./
# 暴露端口
EXPOSE 3000
# 启动应用
CMD ["yarn", "start"]