Update Dockerfile

This commit is contained in:
2025-12-25 10:46:56 +00:00
parent ca358c218a
commit 4ecafb25d2

View File

@@ -1,40 +1,40 @@
# Build stage
FROM node:22-alpine AS builder FROM node:22-alpine AS builder
WORKDIR /app WORKDIR /app
# Dependencies o'rnatish
COPY package*.json ./ COPY package*.json ./
RUN npm install --force RUN npm ci --legacy-peer-deps
# Kodlarni nusxalash va build qilish
COPY . . COPY . .
# Next.js standalone build (optimallashtirilgan)
RUN npm run build RUN npm run build
# Production stage
FROM node:22-alpine AS runner
FROM nginx:alpine WORKDIR /app
# Default html tozalaymiz ENV NODE_ENV=production
RUN rm -rf /usr/share/nginx/html/* ENV PORT=3000
# ❗ MUHIM: .next emas, out papka # Next.js uchun zarur foydalanuvchi yaratish
COPY --from=builder /app/out /usr/share/nginx/html RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Default nginx configni ochiramiz # Faqat zarur fayllarni nusxalash
RUN rm /etc/nginx/conf.d/default.conf 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 # Foydalanuvchi huquqlarini o'zgartirish
RUN printf '%s\n' \ RUN chown -R nextjs:nodejs /app
'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
EXPOSE 80 USER nextjs
CMD ["nginx", "-g", "daemon off;"] EXPOSE 3000
CMD ["node", "server.js"]