
- 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.
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
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.
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.
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.
- 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.
Ask for a second Dockerfile target for development with hot reload and the source folder mounted, keeping production lean.
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 →More like this
- Review and improve a DockerfileChatGPT · Gemini · Claude
- Add secure login to a web appClaude · ChatGPT · Gemini
- Design a REST API for your appChatGPT · Gemini · Claude
- Automate Google Sheets with Apps ScriptClaude · ChatGPT · Gemini
- Build a REST API endpoint with validationClaude · ChatGPT · Gemini



