From 4ecafb25d215dee692f0d2e305e85673c395ce2e Mon Sep 17 00:00:00 2001 From: xoliqberdiyev Date: Thu, 25 Dec 2025 10:46:56 +0000 Subject: [PATCH] Update Dockerfile --- Dockerfile | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5797ed..cdf5bc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,40 @@ +# Build stage FROM node:22-alpine AS builder WORKDIR /app +# Dependencies o'rnatish COPY package*.json ./ -RUN npm install --force +RUN npm ci --legacy-peer-deps +# Kodlarni nusxalash va build qilish COPY . . + +# Next.js standalone build (optimallashtirilgan) RUN npm run build +# Production stage +FROM node:22-alpine AS runner -FROM nginx:alpine +WORKDIR /app -# Default html tozalaymiz -RUN rm -rf /usr/share/nginx/html/* +ENV NODE_ENV=production +ENV PORT=3000 -# ❗ MUHIM: .next emas, out papka -COPY --from=builder /app/out /usr/share/nginx/html +# Next.js uchun zarur foydalanuvchi yaratish +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 -# Default nginx configni o‘chiramiz -RUN rm /etc/nginx/conf.d/default.conf +# Faqat zarur fayllarni nusxalash +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static -# nginx.conf ni bevosita Dockerfile ichida yozamiz -RUN printf '%s\n' \ -'server {' \ -' listen 80;' \ -' server_name _;' \ -'' \ -' root /usr/share/nginx/html;' \ -' index index.html;' \ -'' \ -' location / {' \ -' try_files $uri $uri/ /index.html;' \ -' }' \ -'}' \ -> /etc/nginx/conf.d/default.conf +# Foydalanuvchi huquqlarini o'zgartirish +RUN chown -R nextjs:nodejs /app -EXPOSE 80 +USER nextjs -CMD ["nginx", "-g", "daemon off;"] +EXPOSE 3000 + +CMD ["node", "server.js"] \ No newline at end of file