- Create multi-stage standalone Dockerfile for Next.js frontend (node:20-alpine, non-root nextjs:nodejs user) - Configure output: 'standalone' in refer_landing_page/next.config.js - Add refer_landing_page/.dockerignore for build context optimization - Wire anl-backend and anl-frontend services in root docker-compose.yml with healthchecks, network dependencies, and persistent volume storage
55 lines
1.6 KiB
Docker
55 lines
1.6 KiB
Docker
# ==============================================================================
|
|
# Stage 1: Install dependencies
|
|
# ==============================================================================
|
|
FROM node:20-alpine AS deps
|
|
WORKDIR /app
|
|
|
|
# Install libc6-compat for compatibility
|
|
RUN apk add --no-cache libc6-compat
|
|
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# ==============================================================================
|
|
# Stage 2: Build the Next.js application
|
|
# ==============================================================================
|
|
FROM node:20-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Set build-time environment variables
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV NODE_ENV=production
|
|
|
|
RUN npm run build
|
|
|
|
# ==============================================================================
|
|
# Stage 3: Production runner
|
|
# ==============================================================================
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nextjs
|
|
|
|
# Copy static assets and standalone build output
|
|
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 3000
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1
|
|
|
|
CMD ["node", "server.js"]
|