28 lines
719 B
Docker
28 lines
719 B
Docker
# 分层构建:依赖与代码分离,仅代码变更时只重建 COPY 及以后层
|
|
FROM node:20-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# 使用国内镜像源,加快安装并减少网络卡死
|
|
RUN npm config set registry https://registry.npmmirror.com \
|
|
&& npm config set fetch-retries 5 \
|
|
&& npm config set fetch-timeout 60000 \
|
|
&& npm config set fetch-retry-mintimeout 10000
|
|
|
|
# 依赖层:只有 package.json / package-lock 变更时才重建
|
|
COPY package.json ./
|
|
RUN npm install --prefer-offline --no-audit --progress=false
|
|
|
|
# 代码层:业务代码变更只重建此层及后续 build
|
|
COPY . .
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN npm run build
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["npm", "run", "start"]
|
|
|