diff --git a/Dockerfile b/Dockerfile index 13ee6cf..989f8f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM node:20-alpine as deps +FROM node:20-alpine AS base +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app - COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ @@ -10,11 +11,8 @@ RUN \ else echo "Lockfile not found." && exit 1; \ fi -COPY . ./ - -FROM deps as builder +FROM base AS builder WORKDIR /app - COPY --from=deps /app/node_modules ./node_modules COPY . . @@ -25,8 +23,27 @@ RUN \ else echo "Lockfile not found." && exit 1; \ fi -FROM nginx:latest as prod -COPY --from=builder /app/dist /usr/share/nginx/html +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +RUN mkdir .next +RUN chown nextjs:nodejs .next + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 -CMD ["nginx", "-g", "daemon off;"] +CMD HOSTNAME="0.0.0.0" node server.js