Docker Compose Prompt (Gemini)
docker-compose.yml files often use :latest tags and bind mounts, which cause "works on my machine" problems. This prompt generates configs with pinned tags, named volumes, and proper dependency health checks, so the entire stack starts cleanly every time. The .env.example file prevents the common problem of missing environment variables causing mysterious startup failures. This variant is formatted for Gemini: Optimised for Gemini 1.5 Pro and Gemini Ultra. Uses Google AI markdown formatting conventions.
# Gemini AI Prompt
You are a helpful AI assistant powered by Google Gemini.
## Instructions
You are a DevOps engineer specialising in containerised development environments.
Generate a docker-compose.yml for the following application:
Application services: {{services}}
Environment: {{environment}}
Networking requirements: {{networking}}
Volume requirements: {{volumes}}
Environment variables needed: {{env_vars}}
Additional requirements: {{additional_requirements}}
The docker-compose.yml must:
- Use named volumes for persistent data (not bind mounts for data)
- Define a custom network for inter-service communication
- Use health checks for services that others depend on
- Use ${VARIABLE:-default} syntax for environment variables with sensible defaults
- Pin specific image versions (not :latest)
- Set restart policies appropriate for the environment
Also provide:
1. A .env.example file with all required environment variables
2. A README snippet explaining how to start the stack: `docker compose up -d`
3. Health check commands to verify all services are running
## Output Format
Provide a well-structured response using Markdown headers and code blocks where appropriate.Variables
{{services}}Services needed, e.g., "Node.js API, PostgreSQL, Redis, nginx reverse proxy"{{environment}}Environment type: "local development", "staging", "production"{{networking}}Networking needs, e.g., "API should be accessible externally, database internal only", or "standard"{{volumes}}Data persistence needs, e.g., "persist PostgreSQL data, persist uploaded files", or "None"{{env_vars}}Required environment variables by service, e.g., "postgres: POSTGRES_PASSWORD; api: DATABASE_URL, JWT_SECRET"{{additional_requirements}}Extra requirements, or "None"Example
services: Node.js API (port 3000), PostgreSQL 16, Redis 7 environment: local development networking: expose API on host port 3000, keep DB and Redis internal volumes: persist PostgreSQL data, persist Redis data env_vars: postgres: POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD; api: DATABASE_URL, REDIS_URL, JWT_SECRET additional_requirements: Add pgAdmin for database management
version: '3.8'
services:
api:
build: .
ports: ['3000:3000']
environment:
DATABASE_URL: ${DATABASE_URL:-postgresql://app:secret@postgres:5432/app}
REDIS_URL: ${REDIS_URL:-redis://redis:6379}
JWT_SECRET: ${JWT_SECRET}
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
postgres:
image: postgres:16-alpine
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: pg_isready -U ${POSTGRES_USER:-app}
interval: 5sRelated Tools
FAQ
- What is the difference between depends_on and health checks?
- depends_on alone only waits for the container to start, not for the service inside to be ready. Combine `depends_on` with `condition: service_healthy` and a `healthcheck:` on the dependency to wait until the service is actually accepting connections.
- How do I use docker compose in production?
- Docker Compose is suitable for single-host production deployments. For multi-host deployments, use Docker Swarm or Kubernetes. For production compose files, set restart: always, use secrets instead of environment variables for credentials, and enable resource limits.
- How do I update a single service without restarting the whole stack?
- Run `docker compose up -d --no-deps --build service_name`. The `--no-deps` flag prevents dependent services from also restarting. Use `docker compose pull` first to pull the latest image before restarting.
Related Prompts
docker-compose.yml files often use :latest tags and bind mounts, which cause "works on my ...
Docker Compose Prompt (ChatGPT)docker-compose.yml files often use :latest tags and bind mounts, which cause "works on my ...
Docker Compose Prompt (Claude)docker-compose.yml files often use :latest tags and bind mounts, which cause "works on my ...
Docker Compose Prompt (LLaMA / Ollama)docker-compose.yml files often use :latest tags and bind mounts, which cause "works on my ...
Dockerfile Generation PromptDockerfiles generated without guidance often use :latest tags, run as root, and copy the e...
CI/CD Pipeline Configuration PromptCI/CD configurations involve many interdependent jobs and conditional triggers that are ea...