mirror of
https://github.com/sinodidi/---OS.git
synced 2026-03-22 09:38:06 +08:00
30 lines
559 B
Docker
30 lines
559 B
Docker
# 多阶段构建
|
|
# 阶段1: 构建前端
|
|
FROM node:18-alpine as frontend-builder
|
|
|
|
WORKDIR /app/frontend
|
|
COPY frontend/package*.json ./
|
|
RUN npm install
|
|
COPY frontend/ ./
|
|
RUN npm run build
|
|
|
|
# 阶段2: 构建后端
|
|
FROM node:18-alpine
|
|
|
|
WORKDIR /app
|
|
COPY backend/package*.json ./
|
|
RUN npm install --production
|
|
|
|
# 复制后端代码
|
|
COPY backend/ ./
|
|
# 从前端构建阶段复制构建结果
|
|
COPY --from=frontend-builder /app/frontend/build ./public
|
|
|
|
# 创建数据目录
|
|
RUN mkdir -p /app/data
|
|
|
|
# 暴露端口
|
|
EXPOSE 5000
|
|
|
|
# 启动命令
|
|
CMD ["node", "index.js"] |