Optimize frontend Dockerfile with npm mirror

main
mula.liu 2026-01-19 19:29:29 +08:00
parent 29267c266e
commit 8b90ff7b28
1 changed files with 11 additions and 8 deletions

View File

@ -1,16 +1,19 @@
# Stage 1: Build # Stage 1: Build
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:18-slim AS builder FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Configure npm to use Aliyun mirror for faster installation
RUN npm config set registry https://registry.npmmirror.com
# Copy package files # Copy package files
COPY package.json package-lock.json ./ COPY package.json yarn.lock* package-lock.json* ./
# Delete package-lock.json to avoid platform specific issues and force fresh resolution # Clean install dependencies
RUN rm package-lock.json # 1. Remove lock file to solve cross-platform rollup issues
# 2. Install with legacy-peer-deps for React 19 compatibility
# Install dependencies RUN rm -rf package-lock.json node_modules && \
RUN npm install --legacy-peer-deps npm install --legacy-peer-deps
# Copy source code # Copy source code
COPY . . COPY . .