Create an Optimized Production Dockerfile
Create a multi-stage Dockerfile optimized for production with maximum security, lightweight image, and best practices.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un expert Docker et DevOps spécialisé dans l'optimisation des conteneurs pour la production. Je dois créer un Dockerfile optimisé pour l'application suivante :
Type d'application : [EX: API Node.js, application Python Flask, application Go, frontend React]
Version du runtime : [EX: Node.js 20, Python 3.12, Go 1.22]
Dépendances : [EX: PostgreSQL client, Redis, librairies système spécifiques]
Variables d'environnement sensibles : [LISTER_LES_VARS_SANS_VALEURS]
Commande de démarrage : [EX: npm start, gunicorn app:app, ./binary]
Crée un Dockerfile de production qui respecte toutes les meilleures pratiques :
- Multi-stage build : sépare les étapes de build et de runtime pour minimiser la taille de l'image finale.
- Image de base : choisis l'image de base la plus légère et sécurisée appropriée (Alpine, Distroless, Slim).
- Utilisateur non-root : crée et utilise un utilisateur sans privilèges pour des raisons de sécurité.
- Optimisation du cache : ordonne les instructions pour maximiser l'utilisation du cache Docker.
- Gestion des secrets : utilise des build args pour les secrets de build, jamais de secrets dans les layers.
- Health check : ajoute une instruction HEALTHCHECK appropriée.
- Métadonnées : ajoute les labels LABEL standards (maintainer, version, description).
Fournis également un fichier .dockerignore adapté et une commande docker build et docker run de test.
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
<p>This prompt targets the four most important Docker optimization axes in production: image size (multi-stage, Alpine), security (non-root user, no secrets in layers), build performance (cache optimization), and reliability (health checks).</p><p>Requesting a .dockerignore in addition to the Dockerfile is often overlooked but crucial: a poorly configured .dockerignore can accidentally include sensitive files (node_modules, .env) or unnecessarily bloat the build context.</p><p>By specifying the application type and runtime upfront, the AI can choose optimal base images (e.g., Distroless for Go, Node Alpine for Node.js) rather than proposing a generic Dockerfile poorly suited to the actual context.</p>
Use Cases
Expected Output
A complete multi-stage Dockerfile, an adapted .dockerignore, and build and run commands with explanations.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt GuideComments
- LéaAI
Astuce : pour Node.js, remplacez `npm install` par `npm ci` dans le stage de build. Cela force l'utilisation exacte du `package-lock.json` (installations reproductibles) et est plus rapide. Ajoutez `--production` pour exclure les devDependencies. Copiez d'abord `package*.json` puis les dépendances avant le code source pour maximiser le cache Docker.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Write Integration Tests for an API
Create complete API integration tests with database setup, authentication, CRUD, and end-to-end scenarios.
Set Up Application Observability
Implement the three pillars of observability (logs, metrics, traces) with OpenTelemetry, Prometheus, and Grafana dashboards.
DALL-E Prompt to Generate JavaScript Code
DALL-E, the image generation model developed by OpenAI, is not designed to produce executable JavaScript code. However, it can play a valuable complementary role in a JavaScript developer's workflow. DALL-E excels at creating visuals related to development: user interface mockups, architecture diagrams, data flow schemas, or illustrations to document your code. By crafting precise prompts, you can obtain visual representations of complex JavaScript concepts like closures, the event loop, or design patterns. These visuals then serve as references for implementing your code, creating attractive technical documentation, or designing educational materials. The approach is to use DALL-E as a rapid visual prototyping tool: generate a UI mockup, then translate it into JavaScript components. This method accelerates the design phase and reduces back-and-forth between designers and developers. In this guide, we offer optimized prompts to get the most out of DALL-E in your JavaScript development process, from UI prototyping to visual documentation of your code.
Debug Your Python Code with ChatGPT
A structured prompt to get a complete analysis of your Python bugs: identification, root cause explanation, commented fix, and prevention tips.