Dockerfile Prompt for Production Images
A structured prompt that writes a secure, optimized Dockerfile for your app — multi-stage, small, and cache-friendly — with a real example.
Enhanced prompt — ready to use
ROLE You are a senior DevOps engineer with expertise in containerization and Docker. Your goal is to create an effective Dockerfile tailored to specific application needs. TASK Write a Dockerfile that sets up a container environment for a typical application. Think through this step by step, considering key aspects such as base image selection, dependency installation, file copying, environment variables, exposing necessary ports, and defining the container’s startup command. CONTEXT The request is to create a Dockerfile, presumably for a standard web application or service. The audience includes developers who will build and run the container. Assume a common stack (e.g., Node.js, Python, or similar) unless otherwise specified. REQUIREMENTS - Use best practices in Dockerfile writing for efficiency and security. - Include comments explaining each step. - Consider common optimizations like minimizing image size and leveraging caching. - Before finalizing, verify the Dockerfile syntax and completeness. OUTPUT FORMAT Provide the Dockerfile content as a code block with appropriate comments describing each instruction.
That's what PromptAI produced from this vague prompt: “write a dockerfile”
Example result
```Dockerfile # Use an official Node.js runtime as a parent image. # Here we choose the lightweight 'slim' variant of Node 18 LTS for a balance of size and compatibility. FROM node:18-slim # Set a working directory inside the container WORKDIR /usr/src/app # Copy package.json and package-lock.json first to leverage Docker layer caching # This allows Docker to cache node_modules unless dependencies change COPY package*.json ./ # Install dependencies # Using 'npm ci' for clean install based on package-lock.json for reproducible builds RUN npm ci --production # Copy the rest of the application source code into the container COPY . . # It's a good practice to use non-root user for running the application for security reasons # Create and switch to a non-root user 'appuser' RUN useradd --system --uid 1000 appuser && chown -R appuser /usr/src/app USER appuser # Expose the application's runtime port (adjust as per your app, here assuming 3000) EXPOSE 3000 # Set environment variables - example for NODE_ENV, can be adjusted as needed ENV NODE_ENV=production # Define the startup command to run the app # Assumes the app is started with 'npm start' (script defined in package.json) CMD ["npm", "start"] ```
How to adapt it
- •Tell it your language, version, and start command for an accurate image.
- •Ask for multi-stage builds and a non-root user to keep the image lean and safe.
Have your own rough prompt? Enhance it into a structured prompt like this in one click.
Enhance your own promptMore coding prompts
API Documentation Prompt for Clear Docs
A structured prompt that documents your API endpoint — params, responses, errors, and examples — in clean reference style, with a real example.
Bash Script Prompt for Shell Automation
A structured prompt that writes a safe, portable Bash script for your task — with checks, comments, and a real example output.
Bug Fix Prompt That Finds Root Causes
A structured prompt that diagnoses and fixes a bug — root cause, the fix, and why it works — instead of a guess, with a real example.
Code Comment Prompt for Useful Comments
A structured prompt that adds clear, non-obvious comments and docstrings to your code — explaining why, not just what — with a real example.
Code Review Prompt for Better Feedback
A structured prompt that turns ChatGPT into a thorough code reviewer — bugs, edge cases, readability, and security — with a real example review.
Database Schema Prompt for Clean Data Models
A structured prompt that designs a normalized database schema for your app — tables, keys, and relations — with DDL and a real example.