Files
iam-front/deploy/docker/Dockerfile
2026-02-11 16:30:54 +08:00

60 lines
1.7 KiB
Docker

# =========================================
# Stage 1: Install dependencies (with pnpm)
# =========================================
FROM node:20-alpine AS deps
WORKDIR /app
# Enable pnpm via corepack and configure registry mirror
RUN corepack enable && corepack prepare pnpm@latest --activate \
&& npm config set registry https://registry.npmmirror.com/
# Copy only package files to cache dependency installation
COPY package.json pnpm-lock.yaml* ./
# Install dependencies (frozen-lockfile ensures reproducibility)
RUN pnpm install --frozen-lockfile --prod=false
# =========================================
# Stage 2: Builder (build Next.js app)
# =========================================
FROM node:20-alpine AS builder
WORKDIR /app
# Enable pnpm for potential script usage
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the application
# Note: Next.js telemetry is disabled via env if needed, or disable in next.config.js
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm run build
# =========================================
# Stage 3: Runner (Production image)
# =========================================
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=6020
ENV HOSTNAME="0.0.0.0"
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Copy only necessary files for standalone mode
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 6020
CMD ["node", "server.js"]