DevOps, CI/CD & Cloud
Target: Claude 3.7, Cursor, Windsurf, ChatGPT

Production Dockerfile Multi-Stage Optimization & Hardening

Optimize Dockerfiles for minimal image size, non-root security, layer caching, and CVE vulnerability reduction.

DockerContainersDevOpsSecurityCI/CD

Interactive Prompt Playground

Customize Template Fields
Live replacement
{{DOCKERFILE}}
{{RUNTIME}}
{{TARGET_ARCH}}
Rendered Prompt (Ready to paste)1349 characters
You are a Principal Container Security and DevOps Engineer.

Optimize and harden the following Dockerfile for secure production deployment:

Dockerfile:
```dockerfile
FROM node:20
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
```

Application Runtime: Next.js 15 (standalone output) with Node 22
Target Registry & Architecture: Multi-arch (amd64/arm64) on AWS EKS

Audit and rebuild this container image:
1. **Multi-Stage Build Architecture**:
   - Separate build-time tooling (compilers, devDependencies, header files) from the minimal production runtime image.
   - Use ultra-lean base images (e.g. `alpine`, `distroless`, or `chainguard`).
2. **Layer Caching Optimization**:
   - Order `COPY` commands so frequently changing source code doesn't invalidate heavy dependency installation layers.
3. **Security Hardening**:
   - Enforce non-root user execution (`USER nonroot` / `USER node`).
   - Remove shell utilities, package managers, and root permissions from the final image.
   - Avoid hardcoded tokens or build-args containing secrets.
4. **Signals & Process Management**:
   - Ensure proper `ENTRYPOINT` format so PID 1 forwards SIGTERM signals for graceful container shutdown.
5. **Optimized Dockerfile Output**:
   - Provide the complete, production-hardened Dockerfile with inline annotations.

How to Use This Prompt

  1. Paste your current Dockerfile.
  2. Specify your application framework and deployment platform.
  3. Get a production multi-stage Dockerfile with non-root security and fast layer caching.

Engineering Tips & Best Practices

  • For Next.js apps, enable 'output: standalone' in next.config.js to eliminate 90% of node_modules in the Docker image.

What This Prompt Inspects

Key failure modes, design principles, and quality standards evaluated during execution.

Non-Root Execution

Blocks root user vulnerabilities by switching to dedicated unprivileged users.

Image Size Reduction

Shrinks images by 80%+ by leveraging multi-stage builds and distroless bases.

Layer Cache Invalidation

Copies package.json first so source edits don't trigger full dependency re-installs.

SprintKit Workflow Integrations

Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.

Related Prompts

Explore related developer prompts in this workflow domain.

All Prompts

Kubernetes Deployment, HPA & Resource Limits Review

Audit Kubernetes manifests for CPU/memory requests, readiness/liveness probes, HPA, and Pod Disruption Budgets.

KubernetesK8sDevOpsCloud+1
3 variablesCustomize prompt

GitHub Actions CI/CD Pipeline & Caching Optimizer

Speed up slow GitHub Actions workflows with dependency caching, matrix parallelization, and security secrets.

GitHub ActionsCI/CDDevOpsCaching+1
3 variablesCustomize prompt

Security Vulnerability & OWASP Code Audit

Audit backend and frontend code for OWASP Top 10 vulnerabilities, authentication bypasses, IDOR, and injection flaws.

SecurityOWASPAuthBackend+1
3 variablesCustomize prompt