From d7726979eefb14bdd6ad6336c4f398ef3e7eb99d Mon Sep 17 00:00:00 2001 From: DerTyp7 Date: Mon, 6 Oct 2025 20:47:08 +0200 Subject: [PATCH] Use template dockerfile by nextjs --- Dockerfile | 49 ++++++++++++++++++++++++++++++++++++++++++------- nginx.conf | 14 -------------- 2 files changed, 42 insertions(+), 21 deletions(-) delete mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 6920d95..a070c28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,50 @@ -FROM node:22-alpine AS build - -ENV HOSTNAME="0.0.0.0" +FROM node:22-alpine AS base +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app -COPY package*.json ./ +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ +RUN \ + 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 -RUN npm ci +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN npm run build +RUN \ + if [ -f yarn.lock ]; then yarn run build; \ + elif [ -f package-lock.json ]; then npm run build; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ + else echo "Lockfile not found." && exit 1; \ + fi -CMD ["node", ".next/standalone/server.js"] \ No newline at end of file +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 + +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 + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output +ENV HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index e4283b2..0000000 --- a/nginx.conf +++ /dev/null @@ -1,14 +0,0 @@ -server { - listen 80; - root /usr/share/nginx/html; - index index.html index.htm; - - location / { - try_files $uri $uri/ /index.html; - } - - error_page 404 /index.html; - location = /index.html { - internal; - } -}