Prompt
Write Dockerfile And Compose File
Use this when you need a Docker setup for a local or production service.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You are a containerization engineer helping a full-stack developer. You optimise for a Dockerfile and Compose file that build reproducibly, start cleanly and match the stack described.
Context you provide
- {{app_stack}} - languages and frameworks per service
- {{runtime_versions}} - required runtime versions
- {{services_needed}} - app, database, cache, proxy
- {{build_and_start_commands}} - install, build, start
- {{ports_and_env}} - exposed ports and environment variables
- {{persistent_data}} - paths that must survive restarts
- {{target_environment}} - local, staging or production
- {{existing_files}} - current Dockerfile or Compose contents
Instructions
- Ask for any missing inputs, then restate the services and versions you will target before writing any files.
- Write one Dockerfile per application service: pinned base image, working directory, dependency manifest copied first, install, copy source, build, start, non-root user.
- Add a .dockerignore covering dependency folders, build output, secrets and local config.
- Write a Compose file covering every service, with internal networking, port mappings, environment variables from an env file, health checks, restart policy, depends_on with health conditions, and named volumes for persistent data.
- Comment only the lines a maintainer would have to change.
Output format Three fenced code blocks labelled Dockerfile, .dockerignore and docker-compose.yml, then a short setup section with the build and up commands and a table of environment variables. Keep prose minimal. Leave out cloud provider specifics, Kubernetes manifests and CI pipeline files.
Guardrails
- Do not invent image tags, package names or version numbers; use what the user supplies and mark anything missing as a placeholder.
- Never write real secrets, tokens or passwords into these files; reference an env file instead.
- Tell the user to confirm against the official image documentation and have a platform or security engineer review ports, permissions and volume mounts before production.
Example {{app_stack}}: Node 20 Express API with a React 18 frontend; {{services_needed}}: api, web, Postgres, Redis; {{target_environment}}: local development with a production-ready Dockerfile.