saas_app/Dockerfile
2025-12-09 15:41:51 -03:00

44 lines
1,003 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================
# STAGE 1 Build
# ============================
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
ENV NODE_ENV=production
RUN npm run build
# ============================
# STAGE 2 Runner (standalone)
# ============================
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# 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
# (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
EXPOSE 3000
# Aqui é o ponto chave: NÃO usar "next start"
CMD ["node", "server.js"]