45 lines
1.2 KiB
Docker
45 lines
1.2 KiB
Docker
# Frontend image for Next.js (dev server + standalone production runner)
|
|
|
|
# Dependency + build stage for production
|
|
FROM node:22-bookworm-slim AS builder
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production \
|
|
NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Install dependencies first for better Docker layer caching
|
|
COPY package*.json ./
|
|
RUN npm ci --ignore-scripts
|
|
|
|
# Copy full source and build standalone output
|
|
COPY . .
|
|
RUN npm run build
|
|
|
|
# Dev image keeps the toolchain for next dev
|
|
FROM node:22-bookworm-slim AS dev
|
|
WORKDIR /app
|
|
ENV NODE_ENV=development \
|
|
NEXT_TELEMETRY_DISABLED=1
|
|
COPY package*.json ./
|
|
RUN npm install
|
|
COPY . .
|
|
CMD ["npm", "run", "dev"]
|
|
|
|
# Production runtime: minimal Node image serving the standalone build
|
|
FROM node:22-slim AS runner
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production \
|
|
NEXT_TELEMETRY_DISABLED=1 \
|
|
PORT=3000
|
|
|
|
# Copy only the files required to serve the built app
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
|
|
# Drop privileges to the bundled node user for safety
|
|
USER node
|
|
EXPOSE 3000
|
|
|
|
# Next.js standalone exposes server.js at the root of the standalone output
|
|
CMD ["node", "server.js"]
|