All checks were successful
Docker Build and Push / build-image (push) Successful in 30m16s
39 lines
832 B
Docker
39 lines
832 B
Docker
# 构建阶段
|
||
FROM node:18-alpine AS builder
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 复制package.json和package-lock.json
|
||
COPY package*.json ./
|
||
|
||
# 设置淘宝源并安装依赖
|
||
RUN npm config set registry https://registry.npmmirror.com && npm install
|
||
|
||
# 复制项目文件
|
||
COPY . .
|
||
|
||
# 构建项目
|
||
RUN npm run build
|
||
|
||
# 生产阶段
|
||
FROM node:18-alpine
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 复制必要的文件
|
||
COPY --from=builder /app/package*.json ./
|
||
COPY --from=builder /app/.next ./.next
|
||
COPY --from=builder /app/content ./content/
|
||
# 复制public目录(如果存在)
|
||
COPY --from=builder /app/public* ./public/
|
||
|
||
# 设置淘宝源并安装生产依赖
|
||
RUN npm config set registry https://registry.npmmirror.com && npm install --only=production
|
||
|
||
# 暴露 3000 端口
|
||
EXPOSE 3000
|
||
|
||
# 启动生产服务器
|
||
CMD ["npm", "start"] |