nordicstorium/Dockerfile.prod

59 lines
1.3 KiB
Docker
Raw Normal View History

2026-02-02 15:45:56 +00:00
FROM node:20-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# --- ADD THIS SECTION ---
# Accept the public variables as build arguments
ARG NEXT_PUBLIC_APP_URL
ARG NEXT_PUBLIC_API_URL
# Make them available to the build command
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
# ------------------------
ENV NEXT_TELEMETRY_DISABLED=1
2026-02-02 16:39:07 +00:00
2026-02-02 15:45:56 +00:00
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
2026-02-02 18:35:49 +00:00
# Use existing node user (UID 1000) to match host permissions
# RUN addgroup --system --gid 1001 nodejs
# RUN adduser --system --uid 1001 nextjs
2026-02-02 15:45:56 +00:00
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
2026-02-02 16:06:33 +00:00
RUN mkdir .next
2026-02-02 18:35:49 +00:00
RUN chown node:node .next
2026-02-02 15:45:56 +00:00
# Automatically leverage output traces to reduce image size
2026-02-02 18:35:49 +00:00
COPY --from=builder --chown=node:node /app/.next/standalone ./
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
2026-02-02 15:45:56 +00:00
2026-02-02 18:35:49 +00:00
USER node
2026-02-02 15:45:56 +00:00
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]