generate_docker_compose
Generates a Docker Compose file template for specified services, with optional database support for PostgreSQL and Redis, to simplify environment setup.
Instructions
Generate a Docker Compose file template
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| services | Yes | List of service names to include | |
| include_database | No | Include database services (PostgreSQL, Redis) |
Implementation Reference
- src/services/DockerService.ts:1167-1182 (handler)Main handler function 'generateDockerCompose' that generates a Docker Compose file, writes it to disk, and returns the result.
async generateDockerCompose(services: string[], includeDatabase = false): Promise<ToolResult> { const composeContent = this.generateDockerComposeContent(services, includeDatabase); const composePath = path.join(this.getCurrentWorkspace(), 'docker-compose.yml'); try { await fs.writeFile(composePath, composeContent); return { content: [{ type: 'text', text: `Docker Compose file generated successfully at: ${composePath}\n\nContent:\n${composeContent}`, }], }; } catch (error: any) { throw new Error(`Failed to write Docker Compose file: ${error.message}`); } } - src/services/DockerService.ts:1399-1465 (handler)Private helper 'generateDockerComposeContent' that constructs the actual YAML content for the docker-compose.yml file, including services and optional database (PostgreSQL, Redis) configuration.
private generateDockerComposeContent(services: string[], includeDatabase: boolean): string { let content = `version: '3.8' services: `; // Add main application services services.forEach(service => { content += ` ${service}: build: . ports: - "3000:3000" environment: - NODE_ENV=production volumes: - .:/app - /app/node_modules depends_on: - db networks: - app-network restart: unless-stopped `; }); // Add database if requested if (includeDatabase) { content += ` db: image: postgres:15 environment: POSTGRES_DB: appdb POSTGRES_USER: appuser POSTGRES_PASSWORD: apppass volumes: - postgres_data:/var/lib/postgresql/data ports: - "5432:5432" networks: - app-network restart: unless-stopped redis: image: redis:7-alpine ports: - "6379:6379" networks: - app-network restart: unless-stopped `; } content += `networks: app-network: driver: bridge `; if (includeDatabase) { content += `volumes: postgres_data: `; } return content; } - src/toolDefinitions.ts:604-619 (schema)Schema definition: registers tool name 'generate_docker_compose', description, and inputSchema with 'services' (array of strings) and optional 'include_database' (boolean).
{ name: 'generate_docker_compose', description: 'Generate a Docker Compose file template', inputSchema: { type: 'object', properties: { services: { type: 'array', items: { type: 'string' }, description: 'List of service names to include' }, include_database: { type: 'boolean', description: 'Include database services (PostgreSQL, Redis)' }, }, required: ['services'], }, }, - src/index.ts:223-224 (registration)Registration in the main router: case 'generate_docker_compose' dispatches to dockerService.generateDockerCompose with args.services and args.include_database.
case 'generate_docker_compose': return await this.dockerService.generateDockerCompose(args.services, args.include_database);