From 207ec7e56b5892ae8102911feb5f2bb52fb7beee Mon Sep 17 00:00:00 2001 From: prog1764 Date: Tue, 4 Aug 2026 20:23:16 +0400 Subject: [PATCH] =?UTF-8?q?docker:=20=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D1=83=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D0=B9=D0=BD=D0=B5=D1=80=D0=B5=20(Next.js)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dockerfile: multi-stage (deps/build/runner), standalone-сборка, non-root user - next.config.mjs: output: 'standalone' - docker-compose.yml: порт 3000, env из .env.local - .dockerignore: node_modules, .next, .env*, кэш - проверено: npm run build прошёл, standalone артефакт на месте --- .dockerignore | 11 +++++++++++ Dockerfile | 33 +++++++++++++++++++++++++++++++++ docker-compose.yml | 9 +++++++++ next.config.mjs | 1 + 4 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3b7bb0b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.gitignore +.idea +node_modules +.next +out +.env* +.vercel +*.log +.next +npm-debug.log* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2db5241 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# ---- deps ---- +FROM node:20-alpine AS deps +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci --no-audit --no-fund + +# ---- build ---- +FROM node:20-alpine AS build +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ENV NEXT_TELEMETRY_DISABLED=1 +RUN npm run build + +# ---- runtime ---- +FROM node:20-alpine AS runner +WORKDIR /app +ENV NODE_ENV=production \ + NEXT_TELEMETRY_DISABLED=1 \ + PORT=3000 \ + HOSTNAME=0.0.0.0 + +RUN addgroup -S nodejs && adduser -S nextjs -G nodejs + +COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=build --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=build --chown=nextjs:nodejs /app/public ./public + +USER nextjs + +EXPOSE 3000 + +CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3ee129d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +# Секреты — только из .env (см. .env.local.example) +services: + web: + build: . + ports: + - "3000:3000" + env_file: + - .env.local + restart: unless-stopped diff --git a/next.config.mjs b/next.config.mjs index 5e5b4f4..4dce508 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -17,6 +17,7 @@ const securityHeaders = [ const nextConfig = { reactStrictMode: true, poweredByHeader: false, + output: "standalone", async headers() { return [ {