Founding offer: 50% off your first year

See plans →
Coding

Docker Compose Prompt for Multi-Service Stacks

A structured prompt that writes a compose file with services, networks, volumes, and healthchecks — with a real example file.

Enhanced prompt — ready to use
ROLE You are a senior DevOps engineer with expertise in container orchestration and Docker Compose. Your goal is to create a Docker Compose file tailored to the user's technology stack. TASK Write a Docker Compose file that defines and configures all necessary services for the user's application stack. Think through this step by step to ensure proper service definitions, networking, volumes, and environment variables are included based on typical needs. CONTEXT A user requests a Docker Compose configuration to orchestrate their application stack and its services. No specific technologies or services have been provided, so this should be a general but practical example applicable for common web application components like a backend service, database, and frontend. REQUIREMENTS - Include service definitions for a web application, a database, and any supporting services commonly found in application stacks. - Use appropriate Docker Compose version syntax. - Define networks and volumes where applicable to enable persistence and inter-service communication. - Include environment variables with placeholders for configuration. - Think step by step, consider edge cases such as service dependencies and restart policies. - Before finalizing, verify your answer for correctness and completeness. ASSUMPTIONS - The stack includes at least a web backend service (e.g., Node.js or Python), a database service (e.g., PostgreSQL), and optionally a frontend (e.g., React). - User prefers general guidance that can be customized. OUTPUT FORMAT Provide the Docker Compose file in a properly formatted YAML code block with clear comments explaining each section and service.

or write yours rough and click once

That's what PromptAI produced from this vague prompt: write a docker compose file for my stack

Example result

```yaml version: '3.8' # Use a recent stable Docker Compose version # Define volumes that persist data even if containers stop or are recreated volumes: db_data: # Persist PostgreSQL data outside the container driver: local # Define a user-defined network for all services to communicate easily networks: app_network: driver: bridge services: # Backend service running a typical web app (e.g., Node.js, Python Flask/Django) backend: build: context: ./backend # Path to backend Dockerfile and source code dockerfile: Dockerfile container_name: backend_app restart: always # Restart container unless stopped manually (good for resilience) environment: # Placeholder environment variables - to be replaced with real values or .env files DATABASE_HOST: db DATABASE_PORT: 5432 DATABASE_USER: your_db_user DATABASE_PASSWORD: your_db_password DATABASE_NAME: your_db_name # Additional environment variables for backend can be added here # e.g., SECRET_KEY, API_KEYS, etc. ports: - "8000:8000" # Expose backend on host port 8000 (adjust as needed) depends_on: - db # Ensure db service starts before backend networks: - app_network volumes: - ./backend:/app # Bind mount backend source for live development (optional) # Database service using PostgreSQL, widely used relational database db: image: postgres:15-alpine container_name: postgres_db restart: always environment: POSTGRES_USER: your_db_user POSTGRES_PASSWORD: your_db_password POSTGRES_DB: your_db_name volumes: - db_data:/var/lib/postgresql/data # Persist DB data through named volume ports: - "5432:5432" # Expose DB port on host for local access (optional, remove if not needed) networks: - app_network # Frontend service, e.g. React app served via a simple static server or Node.js frontend: build: context: ./frontend # Path to frontend Dockerfile and source code dockerfile: Dockerfile container_name: frontend_app restart: always environment: # Example environment variables to configure frontend if needed REACT_APP_BACKEND_URL: http://backend:8000 ports: - "3000:3000" # Expose frontend port (default React dev server port) depends_on: - backend # Ensure backend is up before starting frontend networks: - app_network volumes: - ./frontend:/app # Bind mount frontend source for live development (optional) # Notes: # - Replace './backend' and './frontend' folders and Dockerfiles with your project structure. # - Use docker-compose.override.yml for development overrides (e.g., bind mounts, ports). # - Environment variables with placeholders should be secured and configured externally in production. # - Consider adding healthchecks for each service to improve reliability. ```

How to adapt it

  • List your services and which need to talk to which.
  • Ask for dev-vs-prod override guidance so secrets stay out.

Have your own rough prompt? Enhance it in one click.

Enhance your own prompt

Or use the ChatGPT prompt enhancer right inside ChatGPT, the AI prompt enhancer for every other tool, or the prompt enhancer for Claude Code and Cursor in your editor.

More coding prompts