40 lines
762 B
Docker
40 lines
762 B
Docker
# Build stage
|
|
FROM node:22-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Dependencies o'rnatish
|
|
COPY package*.json ./
|
|
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
|
|
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
|
|
# Next.js uchun zarur foydalanuvchi yaratish
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S nextjs -u 1001
|
|
|
|
# Faqat zarur fayllarni nusxalash
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
|
|
# Foydalanuvchi huquqlarini o'zgartirish
|
|
RUN chown -R nextjs:nodejs /app
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["node", "server.js"] |