P
💻DeveloppementIntermediateChatGPT

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 :

  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.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

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

Containerizing applications for productionAuditing existing DockerfilesReducing image size and build time

Expected Output

A complete multi-stage Dockerfile, an adapted .dockerignore, and build and run commands with explanations.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • 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.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Midjourney Prompt for Debugging Code

Midjourney, primarily known for artistic image generation, can play a surprisingly effective role in the code debugging process. By creating visual representations of logical flows, system architectures, or data structures, Midjourney allows developers to step back from their code and identify issues that escape purely textual reading. Visualization is a powerful cognitive tool: turning a complex algorithm into a visual diagram helps spot infinite loops, missing conditional branches, or circular dependencies. Using well-crafted prompts, you can generate conceptual diagrams of your architecture, visual metaphors for understanding data flows, or educational illustrations to document a bug and communicate it to your team. This complementary approach to traditional debugging aligns with the growing trend of visual programming and visual thinking applied to software development. Whether you're facing a stubborn bug or seeking to better understand a legacy system, Midjourney offers a unique perspective to approach your code problems from a new and creative angle.

400
💻DeveloppementIntermediateAll AIs

Adapting an API for Different Clients

Tailoring API responses to client needs

375
💻DeveloppementBeginnerAll AIs

Write an ORM query

Write efficient ORM queries

404
💻DeveloppementIntermediateClaude

Claude Prompt for Creating E2E Tests

End-to-end (E2E) tests are essential to ensure your application works correctly from the end user's perspective. However, writing them is often time-consuming and repetitive: simulating complete user journeys, handling selectors, async waits, and UI state assertions. Claude excels at this task by generating structured, maintainable E2E tests covering both happy paths and edge cases. By providing context about your application — tech stack, test framework, page structure — Claude produces ready-to-run test suites for Playwright, Cypress, or other tools. It understands best practices like data-testid usage, the Page Object Model pattern, and loading state management. Whether starting from scratch or supplementing existing coverage, Claude transforms a functional description into robust tests in seconds, letting you focus on business logic rather than technical plumbing.

454