WriteMyAIPromptFree, no sign-up

AI prompt for writing a Dockerfile

This is a ready-made AI prompt for writing a Dockerfile, written for Claude and free to copy. Most generated Dockerfiles work and are wrong in the same three ways: a single stage that ships the whole toolchain, a `latest` base tag that breaks silently months later, and everything running as root. The prompt below handles that: it is compiled as a writing task, so it carries the structure and the constraints that kind of work needs.

The prompt

Written for Claude. Compiled as a writing task — producing original prose: articles, essays, stories, letters, and long-form copy.

<role>
You are a senior writer and editor with a decade of experience in this exact form.
</role>

<context>
Runtime and version: {{runtime}}. Build steps: {{build}}. What it needs at runtime: {{runtime_deps}}. Where it deploys: {{target}}.
</context>

<task>
Write a Dockerfile for a {{stack}} application.
</task>

<constraints>
- Use a multi-stage build so build tools do not ship in the final image.
- Pin the base image to a specific tag, never latest.
- Run as a non-root user.
- Order layers so dependency installation is cached separately from source.
- Explain each non-obvious line in a comment.
- Write in plain, direct prose. Do not restate the prompt, and do not open with a throat-clearing sentence.
- Vary sentence length. Do not begin consecutive sentences with the same word or structure.
- Do not invent facts, statistics, quotations, or attributed opinions.
</constraints>

<output_format>
Respond with a single fenced code block containing the complete implementation, then a short note covering anything the reader needs to know before running it.
</output_format>

<success_criteria>
Before you finish, check the output against every item below and fix anything that fails.

- The image builds and runs unchanged.
- No build-time tooling in the final layer.
</success_criteria>

Now, write a Dockerfile for a {{stack}} application.

Optional: start the reply with ``` to force the output straight into shape.

Open this in the prompt builder to add your own context and see what would improve it most.

What makes writing a Dockerfile hard to prompt for

Most generated Dockerfiles work and are wrong in the same three ways: a single stage that ships the whole toolchain, a `latest` base tag that breaks silently months later, and everything running as root.

Why this prompt works

Background comes before the instruction
The model reads the situation before it learns what to do with it, which stops the instruction being diluted by everything that follows. The task is then restated as the final line, where models weight it most heavily.
Rules a writing task assumes but nobody writes down
Write in plain, direct prose. Do not restate the prompt, and do not open with a throat-clearing sentence. Vary sentence length. Do not begin consecutive sentences with the same word or structure. These are added automatically because leaving them implicit is the most common reason this kind of output disappoints.
Success criteria the model checks itself against
Stating how the output will be judged gives the model something concrete to verify before it finishes. Prompts without criteria produce work that is plausible but incomplete, because nothing defined when it was done.
A prefill that removes the preamble
Starting the reply with ````` forces the output straight into the required shape and removes the "Sure, here is..." opener entirely.

What to replace

PlaceholderWhat to put there
{{runtime}}Your runtime.
{{build}}Your build.
{{runtime_deps}}Your runtime deps.
{{target}}Your target.
{{stack}}Your stack.

Check the output before you use it

  • Check the final stage contains no compilers or package managers.
  • Confirm the base image is pinned to a specific version, not a floating tag.
  • Look for a USER directive. If the container runs as root, fix it before deploying.

The same prompt for other models

Identical content, packaged the way each model reads most reliably.

ChatGPT

## Role

You are a senior writer and editor with a decade of experience in this exact form.

## Context

Runtime and version: {{runtime}}. Build steps: {{build}}. What it needs at runtime: {{runtime_deps}}. Where it deploys: {{target}}.

## Task

Write a Dockerfile for a {{stack}} application.

## Constraints

- Use a multi-stage build so build tools do not ship in the final image.
- Pin the base image to a specific tag, never latest.
- Run as a non-root user.
- Order layers so dependency installation is cached separately from source.
- Explain each non-obvious line in a comment.
- Write in plain, direct prose. Do not restate the prompt, and do not open with a throat-clearing sentence.
- Vary sentence length. Do not begin consecutive sentences with the same word or structure.
- Do not invent facts, statistics, quotations, or attributed opinions.

## Output format

Respond with a single fenced code block containing the complete implementation, then a short note covering anything the reader needs to know before running it.

## Success criteria

Before you finish, check the output against every item below and fix anything that fails.

- The image builds and runs unchanged.
- No build-time tooling in the final layer.

Now, write a Dockerfile for a {{stack}} application.

Gemini

**Task**

Write a Dockerfile for a {{stack}} application.

**Role**

You are a senior writer and editor with a decade of experience in this exact form.

**Context**

Runtime and version: {{runtime}}. Build steps: {{build}}. What it needs at runtime: {{runtime_deps}}. Where it deploys: {{target}}.

**Constraints**

- Use a multi-stage build so build tools do not ship in the final image.
- Pin the base image to a specific tag, never latest.
- Run as a non-root user.
- Order layers so dependency installation is cached separately from source.
- Explain each non-obvious line in a comment.
- Write in plain, direct prose. Do not restate the prompt, and do not open with a throat-clearing sentence.
- Vary sentence length. Do not begin consecutive sentences with the same word or structure.
- Do not invent facts, statistics, quotations, or attributed opinions.

**Output format**

Respond with a single fenced code block containing the complete implementation, then a short note covering anything the reader needs to know before running it.

**Success criteria**

Before you finish, check the output against every item below and fix anything that fails.

- The image builds and runs unchanged.
- No build-time tooling in the final layer.

Now, write a Dockerfile for a {{stack}} application.

Common questions

Why should a Dockerfile use multi-stage builds?
Because the tools needed to build an application are not needed to run it. A single-stage image ships compilers, package managers and source code to production, which is larger, slower to pull, and a wider attack surface.
Why not use the latest tag for a base image?
Because the image you build today and the one you build in six months will differ with no change on your side. Pinning makes builds reproducible and turns an upgrade into a deliberate, reviewable commit.
Which AI model is best for writing a Dockerfile?
All of them handle this; what changes is the packaging. This page shows the same prompt written for Claude, ChatGPT, Gemini. Claude follows XML-delimited structure most reliably, ChatGPT works best with markdown headings, and Gemini prefers the task stated before the material. The content of the prompt is identical in each.
Can I change this prompt for my own situation?
Yes, and you should. Replace the placeholders with your own details, then open it in the builder to add context specific to you. The builder scores what you supply and tells you exactly which missing piece would improve it most.
Why does this prompt include rules I did not ask for?
Because writing tasks carry requirements that experienced practitioners apply automatically and rarely write down. The compiler adds them so the output does not fail on something obvious. Every added rule is listed on the how it works page.

Browse all ready-made prompts, the full prompt library, or read the guides.