1541
This commit is contained in:
parent
c6217b0520
commit
3eb0bd6f0e
1 changed files with 17 additions and 16 deletions
33
Dockerfile
33
Dockerfile
|
|
@ -1,5 +1,5 @@
|
|||
# ============================
|
||||
# STAGE 1 – Build da aplicação
|
||||
# STAGE 1 – Build
|
||||
# ============================
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
|
|
@ -10,34 +10,35 @@ RUN npm ci
|
|||
|
||||
COPY . .
|
||||
|
||||
# Garante build de produção
|
||||
ENV NODE_ENV=production
|
||||
RUN npm run build
|
||||
|
||||
# =============================
|
||||
# STAGE 2 – Produção (Runner)
|
||||
# =============================
|
||||
# ============================
|
||||
# STAGE 2 – Runner (standalone)
|
||||
# ============================
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Força modo produção
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
# Copia somente o necessário
|
||||
# Copia o standalone e os assets estáticos
|
||||
COPY --from=builder /app/.next/standalone ./ # traz server.js e a app standalone
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/package*.json ./
|
||||
COPY --from=builder /app/next.config.* ./
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
|
||||
# Segurança: executa como usuário não-root
|
||||
RUN addgroup -S nodejs && adduser -S nextjs -G nodejs
|
||||
# (Opcional, mas útil para dependências em runtime)
|
||||
COPY --from=builder /app/package*.json ./
|
||||
|
||||
# Cria usuário não-root e dá permissão
|
||||
RUN addgroup -S nodejs && adduser -S nextjs -G nodejs \
|
||||
&& mkdir -p .next/cache/images \
|
||||
&& chown -R nextjs:nodejs /app
|
||||
|
||||
USER nextjs
|
||||
|
||||
# Porta padrão
|
||||
EXPOSE 3000
|
||||
|
||||
# Comando fixo (força produção)
|
||||
CMD ["sh", "-c", "NODE_ENV=production npm start"]
|
||||
# Aqui é o ponto chave: NÃO usar "next start"
|
||||
CMD ["node", "server.js"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue