更新 Dockerfile
This commit is contained in:
32
Dockerfile
32
Dockerfile
@ -1,27 +1,39 @@
|
|||||||
|
# ---- Build stage ----
|
||||||
FROM node:20-slim AS build
|
FROM node:20-slim AS build
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
|
||||||
RUN npm run build # 如果有前端构建过程,例如 React/Vue
|
|
||||||
|
|
||||||
# ---- Runtime 镜像 ----
|
# 拷贝前端和后端
|
||||||
|
COPY dist/ ./dist
|
||||||
|
COPY public/ ./public
|
||||||
|
COPY server/ ./server
|
||||||
|
COPY src/ ./src
|
||||||
|
COPY index.html ./
|
||||||
|
|
||||||
|
# 如果前端需要构建
|
||||||
|
# RUN npm run build
|
||||||
|
|
||||||
|
# ---- Runtime stage ----
|
||||||
FROM nginx:1.27-alpine
|
FROM nginx:1.27-alpine
|
||||||
|
|
||||||
# 安装 Node.js
|
# 安装 Node.js 运行环境
|
||||||
RUN apk add --no-cache nodejs npm
|
RUN apk add --no-cache nodejs npm
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 复制 Node.js 应用
|
# 拷贝 Node.js 后端
|
||||||
COPY --from=build /app /app
|
COPY --from=build /app/server /app/server
|
||||||
|
|
||||||
# 拷贝前端静态文件到 nginx 路径
|
# 拷贝前端静态文件
|
||||||
RUN mkdir -p /usr/share/nginx/html && \
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
cp -r /app/dist/* /usr/share/nginx/html/
|
COPY --from=build /app/public /usr/share/nginx/html/public
|
||||||
|
COPY --from=build /app/index.html /usr/share/nginx/html/
|
||||||
|
|
||||||
# 拷贝 Nginx 配置
|
# Nginx 配置
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
# 启动脚本
|
# 启动脚本
|
||||||
|
|||||||
Reference in New Issue
Block a user