⌨️ Codingintermediatedockerdevopscontainerizationdeployment

Write a Dockerfile for Any Application

Generate a production-ready, optimized Dockerfile with multi-stage builds, security best practices, and caching.

The Prompt

prompt.txt
Write a production-ready Dockerfile for the following application. Include:
1. Multi-stage build (build stage + lean production stage)
2. Minimal base image (alpine or distroless where possible)
3. Non-root user for security
4. Layer caching optimization (dependencies before source code)
5. HEALTHCHECK instruction
6. Environment variable handling
7. Comments explaining non-obvious choices

Application details:
- Language/runtime: [NODE.JS/PYTHON/GO/JAVA — specify version]
- Build command: [e.g., npm run build]
- Start command: [e.g., node dist/server.js]
- Exposed port: [e.g., 3000]
- Any special requirements: [e.g., needs ffmpeg, specific env vars]

Example Output

Generated a 3-stage Dockerfile: deps stage installs only production node_modules, builder stage compiles TypeScript, runner stage is node:20-alpine with a non-root 'nextjs' user, HEALTHCHECK on /api/health, and a .dockerignore recommendation.

FAQ

Which AI model is best for Write a Dockerfile for Any Application?

GPT-4o or Claude Sonnet 4. Both are strong on DevOps tasks.

How do I use the Write a Dockerfile for Any Application prompt?

Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Generated a 3-stage Dockerfile: deps stage installs only production node_modules, builder stage compiles TypeScript, runner stage is node:20-alpine with a non-root 'nextjs' user, HEALTHCHECK on /api/health, and a .dockerignore recommendation.