# Stage 1: Build # Change from node:18-alpine to node:22-alpine FROM node:22-alpine AS builder WORKDIR /app # Build arguments - MUST be before COPY to be available during build ARG NEXT_PUBLIC_API_URL ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} # Copy package files COPY package.json package-lock.json ./ # Install ALL dependencies (including dev dependencies for build) RUN npm ci # Copy source code COPY . . # Build the app RUN npm run build # Stage 2: Run # Change from node:18-alpine to node:22-alpine FROM node:22-alpine AS runner WORKDIR /app # Set to production ENV NODE_ENV=production # Runtime environment variable ARG NEXT_PUBLIC_API_URL ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} # Copy necessary files from the standalone build COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static # Create cache directory with proper permissions RUN mkdir -p .next/cache/images && \ chmod -R 777 .next/cache # Expose port EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" # Set node options to fix the IPv6 issue we discussed earlier ENV NODE_OPTIONS="--dns-result-order=ipv4first" # Start the app CMD ["node", "server.js"]