Founding offer: 50% off your first year

See plans →
Coding

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.

or write yours rough and click once

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 in one click.

Enhance your own prompt

Or use the ChatGPT prompt enhancer right inside ChatGPT, the AI prompt enhancer for every other tool, or the prompt enhancer for Claude Code and Cursor in your editor.

More coding prompts