Files

77 lines
1.8 KiB
Docker
Raw Permalink Normal View History

2026-03-25 14:58:27 +01:00
# syntax=docker.io/docker/dockerfile:1
2026-04-10 15:39:03 +01:00
############################
# Base image
############################
2026-03-25 14:58:27 +01:00
FROM node:22-alpine AS base
2026-04-10 15:39:03 +01:00
WORKDIR /app
2026-03-25 14:58:27 +01:00
2026-04-10 15:39:03 +01:00
############################
# Dependencies
############################
2026-03-25 14:58:27 +01:00
FROM base AS deps
2026-04-10 15:39:03 +01:00
2026-03-25 14:58:27 +01:00
RUN apk add --no-cache libc6-compat
2026-04-10 15:39:03 +01:00
# Copy package files
2026-03-25 14:58:27 +01:00
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
2026-04-10 15:39:03 +01:00
# Install dependencies
2026-03-25 14:58:27 +01:00
RUN \
2026-04-10 15:39:03 +01:00
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
2026-03-25 14:58:27 +01:00
2026-04-10 15:39:03 +01:00
############################
# Builder
############################
2026-03-25 14:58:27 +01:00
FROM base AS builder
WORKDIR /app
2026-04-10 15:39:03 +01:00
2026-03-25 14:58:27 +01:00
COPY --from=deps /app/node_modules ./node_modules
COPY . .
2026-04-10 15:39:03 +01:00
# Disable telemetry during build (optional)
ENV NEXT_TELEMETRY_DISABLED=1
2026-03-25 14:58:27 +01:00
2026-04-10 15:39:03 +01:00
# Build Next.js app
2026-03-25 14:58:27 +01:00
RUN \
2026-04-10 15:39:03 +01:00
if [ -f yarn.lock ]; then yarn build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm build; \
else echo "Lockfile not found." && exit 1; \
fi
############################
# Runner (production)
############################
FROM node:22-alpine AS runner
2026-03-25 14:58:27 +01:00
WORKDIR /app
ENV NODE_ENV=production
2026-04-10 15:39:03 +01:00
ENV NEXT_TELEMETRY_DISABLED=1
2026-03-25 14:58:27 +01:00
2026-04-10 15:39:03 +01:00
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
2026-03-25 14:58:27 +01:00
2026-04-10 21:21:17 +01:00
# Copy standalone build and static files
2026-03-25 14:58:27 +01:00
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
2026-04-10 21:21:17 +01:00
# 1. Create the specific cache directory Next.js is looking for
# 2. Give ownership to the 'nextjs' user
RUN mkdir -p /app/.next/cache/images && chown -R nextjs:nodejs /app/.next
2026-04-10 15:39:03 +01:00
2026-03-25 14:58:27 +01:00
USER nextjs
2026-04-10 21:21:17 +01:00
EXPOSE 3000
2026-03-25 14:58:27 +01:00
ENV PORT=3000
2026-04-10 15:39:03 +01:00
ENV HOSTNAME=0.0.0.0
2026-03-25 14:58:27 +01:00
CMD ["node", "server.js"]