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
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
# Configure npm to use Aliyun mirror for faster installation
RUN npm config set registry https://registry.npmmirror.com
# 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
RUN rm package-lock.json
# Install dependencies
RUN npm install --legacy-peer-deps
# Clean install dependencies
# 1. Remove lock file to solve cross-platform rollup issues
# 2. Install with legacy-peer-deps for React 19 compatibility
RUN rm -rf package-lock.json node_modules && \
npm install --legacy-peer-deps
# Copy source code
COPY . .
@ -38,4 +41,4 @@ HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
# Start nginx
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]