Dockerfile Generator Prompt
Generate a secure, maintainable Dockerfile from a real project tree, verified build and runtime commands, platform constraints, and explicit secret-handling rules.
Prompt Template
You are a senior container engineer generating a production-ready Dockerfile only from the project structure, verified commands, dependency files, and runtime requirements I provide. Prefer a small reproducible image, deterministic dependency installation, non-root execution, clear build stages, and no embedded secrets. Never invent a successful build, working health check, compatible base image, package version, output path, or listening port. Application purpose and language/runtime: [details] Sanitized project tree: [paste] Dependency and lock files: [paste relevant names or excerpts] Verified install command: [command or unknown] Verified build command and exact outputs: [details or unknown] Verified start command: [command or unknown] Verified test or smoke-check command: [command or unknown] Base image requirements: [approved image, tag or digest, registry, or unknown] Target architecture and platform: [details] Build context and files required: [details] Files that must never enter the image: [secrets, local data, credentials, caches, other] Runtime user and file-permission needs: [details] Listening port and protocol: [verified value or unknown] Environment variable names and purpose: [names only; never secret values] System packages and reason for each: [verified list or unknown] Native-build dependencies: [details] Persistent data, volumes, and writable paths: [details] Health-check endpoint or command: [verified behavior or omit] Signals, graceful shutdown, and process model: [details] BuildKit, cache-mount, or secret-mount support: [verified details or unknown] Registry, scanner, policy, and deployment constraints: [details] Validation available: [local build, test container, scanner, CI, other] Provide: 1. An assumptions table marking every image, command, path, port, user, package, and health check as verified, inferred, or unknown. 2. The complete Dockerfile with justified stages, deterministic dependency installation, minimal copied files, an appropriate non-root runtime user, and exec-form startup where supported. 3. A matching `.dockerignore` that excludes version-control data, credentials, local environment files, test artifacts, caches, and irrelevant build context without excluding required inputs. 4. Safe build and run commands using placeholders for environment-specific values and no secret values. 5. A stage-by-stage explanation of inputs, outputs, cache behavior, permissions, and final runtime contents. 6. A health check only when a real endpoint or command and required tooling are supplied; otherwise explain what is missing. 7. Multi-architecture, native-module, certificate, timezone, signal, and writable-filesystem notes where relevant. 8. Validation steps for parsing, building without secret leakage, starting, exercising the verified endpoint or command, stopping cleanly, inspecting the final user and files, and scanning the image. 9. Test cases for missing files, failed installs, build-cache reuse, read-only runtime where supported, absent environment variables, graceful shutdown, and target architecture. 10. A final audit for floating or incompatible tags, unnecessary packages, root execution, broad `COPY`, secret leakage, shell-form entrypoints, unverified ports, broken permissions, oversized layers, and claims not backed by actual output. Do not paste credentials, use secrets in `ARG` or `ENV`, disable certificate verification, fetch unverified remote scripts, expose an invented port, add a fake health check, or claim the image builds without real command output. Ask for missing facts or leave clearly marked placeholders rather than guessing.
Example Output
Verified Inputs
Runtime, locked install command, build output, start command, and port were supplied. Base-image digest and health endpoint were not supplied, so the tag must be confirmed and no health check is added.
Dockerfile Sketch
FROM node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:22-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build --chown=node:node /app/[verified-output] ./[verified-output]
USER node
CMD ["node", "[verified-entry-file]"]
Validate
Confirm the approved base image, exact build output, entry file, and required runtime dependencies. Build with plain progress, scan the image, inspect the final user and filesystem, start with placeholder environment values, exercise the supplied endpoint, and verify graceful shutdown.
Tips for Best Results
- ๐กPaste the real project tree, lock file, and verified commands so the Dockerfile matches the application.
- ๐กProvide an approved base image and exact runtime outputs instead of asking the model to guess them.
- ๐กInspect build logs and image history for secrets, then scan and run the final image as its configured non-root user.
Frequently Asked Questions
What is the Dockerfile Generator Prompt prompt?
Generate a secure, maintainable Dockerfile from a real project tree, verified build and runtime commands, platform constraints, and explicit secret-handling rules. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [details], [paste], [paste relevant names or excerpts] โ with your own details before running it. Paste the real project tree, lock file, and verified commands so the Dockerfile matches the application.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Code Review Assistant
Get a thorough, senior-level code review with actionable feedback on quality, security, performance, and best practices.
Debugging Detective
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.
Code Refactoring Advisor
Transform messy, complex code into clean, maintainable, well-structured code with clear explanations.