Example result: Write a Dockerfile for your app
AI-generated example · Build · Docker
Updated

Write a Dockerfile for your app

This prompt writes a Dockerfile for your app with a small base image, cached layers, a non-root user and a health check. It adds a docker-compose file for local development and keeps secrets out of the image.

text-code-dockerfile-for-app — claude — 78 words

Act as a DevOps engineer.

App: [e.g. a FastAPI app with a requirements.txt]
How it runs locally: [COMMANDS]
Needs: [e.g. Postgres, Redis, env vars for API keys]

Write a production-ready Dockerfile with a small base image, a multi-stage build if it helps, a non-root user, cached dependency layers and a health check. Add a docker-compose.yml for local development with the services it needs, and a .dockerignore. Explain each important line briefly, and keep secrets out of the image.

Check the image size with docker images. If it is over 1 GB, ask the AI to make it smaller.

Get a better result

What you will get

A production Dockerfile with a small base image, cached dependency layers, a non-root user and a health check, plus a docker-compose.yml for local services, a .dockerignore and short notes on the important lines.

Why it works

Listing how the app runs locally gives the model the real start command instead of a guess. Each requirement in the prompt maps to a common production mistake: huge images, running as root, slow rebuilds and secrets baked in. The compose file covers the services you need day to day, so the setup works on a new laptop, not just on the server.

Common mistake

The image rebuilds every dependency on each code change.

Fix: Ask it to copy the dependency file and install before copying the rest of the code, so the install layer is cached.

Also watch for
  • An .env file ends up inside the image. Check the .dockerignore lists .env and any key files, and pass secrets at run time as the prompt asks.
  • The health check calls a route your app does not have. Tell it which route returns a simple OK, or ask it to add a tiny health route to your app as well.
Try a variation: add a dev container

Ask for a second Dockerfile target for development with hot reload and the source folder mounted, keeping production lean.

Still not right? Reply with this

Here is my build output and the image size: [PASTE]. Make the image smaller and the slowest step faster.

More chat & writing prompts

See all 465 →