使用多阶段构建,Docker 层缓存管理 npm install
This commit is contained in:
+14
-5
@@ -1,10 +1,19 @@
|
||||
# --- 构建阶段 ---
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# 先复制依赖描述文件,利用层缓存
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm install
|
||||
|
||||
# 再复制源码,构建
|
||||
COPY . .
|
||||
RUN npm run type-check && npm run build
|
||||
|
||||
# --- 生产阶段 ---
|
||||
FROM nginx:alpine
|
||||
|
||||
# 安装 curl 用于健康检查
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
COPY dist/ /usr/share/nginx/html/
|
||||
COPY --from=builder /app/dist/ /usr/share/nginx/html/
|
||||
RUN chmod -R 755 /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
Reference in New Issue
Block a user