Create an optimized Dockerfile for production
Create an optimized multi-stage Dockerfile 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 : 1. **Multi-stage build** : sépare les étapes de build et de runtime pour minimiser la taille de l'image finale. 2. **Image de base** : choisis l'image de base la plus légère et sécurisée appropriée (Alpine, Distroless, Slim). 3. **Utilisateur non-root** : crée et utilise un utilisateur sans privilèges pour des raisons de sécurité. 4. **Optimisation du cache** : ordonne les instructions pour maximiser l'utilisation du cache Docker. 5. **Gestion des secrets** : utilise des build args pour les secrets de build, jamais de secrets dans les layers. 6. **Health check** : ajoute une instruction HEALTHCHECK appropriée. 7. **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.
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>The request for 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 inflate the build context.</p><p>By specifying the application type and runtime from the start, the AI can choose optimal base images (for example Distroless for Go, Node Alpine for Node.js) rather than proposing a generic Dockerfile poorly suited to the real context.</p>
Use Cases
Expected Output
A complete multi-stage Dockerfile, an appropriate .dockerignore and the 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 GuideGlossary Terms
Similar Prompts
Implement robust error handling in Node.js
Create a professional Node.js error handling architecture with custom error classes, centralized middleware and monitoring.
Learn the basics of Git for beginners
Learn Git from scratch with illustrated explanations, concrete examples, a practical workflow and a cheatsheet of essential commands.
Define a Git strategy for a team
Define a comprehensive Git strategy adapted to your team: branching model, conventions, code review and release management.
Write integration tests for an API
Create comprehensive API integration tests with database setup, authentication, CRUD and end-to-end scenarios.