Skip to content

Commit b559163

Browse files
Update Dockerfile
1 parent 3715962 commit b559163

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
FROM node:22.18.0-alpine3.22 AS build
1+
# syntax=docker/dockerfile:1.7
2+
FROM --platform=$BUILDPLATFORM node:22.18.0-alpine3.22 AS build
23
WORKDIR /app
4+
5+
# 若依赖含原生扩展,可加编译工具(按需启用)
6+
# RUN apk add --no-cache --virtual .build-deps python3 make g++
7+
8+
# Node 22 使用 Corepack 管理 Yarn
9+
RUN apk add --no-cache libc6-compat && corepack enable && corepack prepare yarn@stable --activate
10+
11+
# 先拷贝依赖清单,利用缓存
12+
COPY package.json yarn.lock ./
13+
RUN yarn --version && node -v && yarn install --immutable
14+
15+
# 再拷贝源码并构建
316
COPY . .
4-
RUN yarn install
517
RUN yarn build
618

7-
FROM nginx:1.24-alpine
19+
FROM --platform=$TARGETPLATFORM nginx:1.24-alpine
820
COPY --from=build /app/dist /usr/share/nginx/html
921
EXPOSE 80
10-
CMD [ "nginx", "-g", "daemon off;" ]
22+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)