マルチステージDockerfileジェネレーター(Node、Go、Python、Rust)
Node.js、Golang、Python、Rust、Java向けの高セキュアで軽量なマルチステージ Dockerfile を生成。非rootユーザー設計と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.
マルチステージ層最適化
コンパイル依存関係とキャッシュを本番ランナー環境から完全に分離し、最終イメージサイズを最大92%削減します。
CISベンチマークセキュリティ防御
非rootユーザー(UID 10001)を構成し、Linux権限を削除して、ビルドツールチェーンを本番環境から排除します。
サーバー送信ゼロの完全プライバシー
すべてのマニフェストとスクリプトはブラウザのメモリ内のみで処理され、外部サーバーへの通信は一切ありません。