Update Dockerfile

This commit is contained in:
2025-12-25 10:55:48 +00:00
parent e7b445c258
commit 45ef2c4b58

View File

@@ -13,37 +13,58 @@ COPY . .
# Environment variables (agar kerak bo'lsa) # Environment variables (agar kerak bo'lsa)
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
# Next.js build # Next.js static export
RUN npm run build RUN npm run build
# Production stage # Production stage - Nginx
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 # ❗ MUHIM: Next.js static export - out papka
ENV PORT=3000 COPY --from=builder /app/out /usr/share/nginx/html
# Next.js uchun zarur foydalanuvchi yaratish # Default nginx configni o'chiramiz
RUN addgroup -g 1001 -S nodejs RUN rm /etc/nginx/conf.d/default.conf
RUN adduser -S nextjs -u 1001
# Package.json va node_modules nusxalash # nginx.conf ni bevosita Dockerfile ichida yozamiz
COPY --from=builder /app/package*.json ./ RUN printf '%s\n' \
COPY --from=builder /app/node_modules ./node_modules 'server {' \
' listen 80;' \
' server_name _;' \
'' \
' root /usr/share/nginx/html;' \
' index index.html;' \
'' \
' # Gzip compression' \
' gzip on;' \
' gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript;' \
'' \
' # Cache static assets' \
' location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {' \
' expires 1y;' \
' add_header Cache-Control "public, immutable";' \
' }' \
'' \
' # Next.js _next static files' \
' location /_next/static/ {' \
' expires 1y;' \
' add_header Cache-Control "public, immutable";' \
' }' \
'' \
' # SPA routing - barcha requestlarni index.html ga yo'\''naltirish' \
' location / {' \
' try_files $uri $uri/ $uri.html /index.html;' \
' }' \
'' \
' # Security headers' \
' add_header X-Frame-Options "SAMEORIGIN" always;' \
' add_header X-Content-Type-Options "nosniff" always;' \
' add_header X-XSS-Protection "1; mode=block" always;' \
'}' \
> /etc/nginx/conf.d/default.conf
# Build qilingan fayllarni nusxalash EXPOSE 80
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
# next.config kerak bo'lsa CMD ["nginx", "-g", "daemon off;"]
COPY --from=builder /app/next.config.* ./
# Foydalanuvchi huquqlarini o'zgartirish
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
CMD ["npm", "start"]