Update Dockerfile
This commit is contained in:
48
Dockerfile
48
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"]
|
||||
Reference in New Issue
Block a user