Gerador de Dockerfile Multi-Stage (Node, Go, Python, Rust)
Crie Dockerfiles multi-stage seguros e ultraleves para Node.js, Golang, Python, Rust e Java com execução não root e otimização de cache BuildKit.
# =========================================================================# Multi-Stage Dockerfile: Next.js Standalone (Hardened & Layer-Cached)# Generated by ToolsAA Multi-Stage Dockerfile Generator# =========================================================================# syntax=docker/dockerfile:1.6
# -------------------------------------------------------------------------# Stage 1: Dependencies Resolution# -------------------------------------------------------------------------FROM node:22-alpine AS depsWORKDIR /app
# Install libc6-compat if Alpine (required for some Node native extensions)RUN apk add --no-cache libc6-compat
# Install package manager lockfiles first to leverage layer cachingCOPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* bun.lockb* ./RUN --mount=type=cache,target=/root/.npm \ if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm install --frozen-lockfile; \ elif [ -f yarn.lock ]; then yarn --frozen-lockfile; \ elif [ -f bun.lockb ]; then npm install -g bun && bun install --frozen-lockfile; \ else npm ci; fi
# -------------------------------------------------------------------------# Stage 2: Application Builder# -------------------------------------------------------------------------FROM node:22-alpine AS builderWORKDIR /app
COPY --from=deps /app/node_modules ./node_modulesCOPY . .
# Disable Next.js telemetry during compilationENV NEXT_TELEMETRY_DISABLED=1ENV NODE_ENV=production
RUN --mount=type=cache,target=/app/.next/cache \ if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ elif [ -f yarn.lock ]; then yarn build; \ else npm run build; fi
# -------------------------------------------------------------------------# Stage 3: Production Minimal Runner# -------------------------------------------------------------------------FROM node:22-alpine AS runnerWORKDIR /app
ENV NODE_ENV=production \ PORT=3000 \ NEXT_TELEMETRY_DISABLED=1ENV NODE_ENV=productionENV PORT=3000ENV HOSTNAME="0.0.0.0"
# Security: Create unprivileged system group and userRUN addgroup -g 10001 -S nodejs && \ adduser -u 10001 -S -G nodejs nextjs# Copy public static assets and standalone bundleCOPY --from=builder /app/public ./publicCOPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/api/health || exit 1EXPOSE 3000
USER nextjsCMD ["node", "server.js"]
Pruned compilation tools and devDependencies from runner stage.
UID 10001 unprivileged non-root execution with dropped capabilities.
Sub-second rebuilds via lockfile pre-caching and BuildKit mounts.
Otimização Multi-Stage em Camadas
Isola dependências de compilação e caches do ambiente de produção, reduzindo a imagem final em até 92%.
Diretrizes de Segurança CIS Benchmark
Configura usuário não-root (UID 10001), descarta capabilities desnecessárias e remove ferramentas de build da produção.
Privacidade com Zero Envio ao Servidor
Todos os manifestos e arquivos de configuração são processados exclusivamente na memória do navegador.