Generate Production-Ready Docker Compose Files
Expert Docker Compose skill that generates production-ready multi-container configurations with service isolation, health checks, network segmentation, and
Why it matters
Automate the creation of robust and scalable Docker Compose configurations for multi-container applications. This asset ensures best practices in service isolation, environment parity, and resource management for efficient development and deployment.
Outcomes
What it gets done
Generate Docker Compose files with defined service dependencies and networking.
Implement resource management, health checks, and volume strategies.
Configure environment variables, secrets, and multi-environment setups.
Incorporate production-ready patterns for security and performance.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-docker-compose-creator | bash Capabilities
What this skill does
Writes source code or scripts from a description.
Runs build pipelines, tests, and deploys to environments.
Traces errors to their root cause and suggests fixes.
Analyzes code for bugs, style issues, and improvements.
Overview
Docker Compose Creator Agent
What it does
A Docker Compose configuration generator that creates multi-container application definitions following container orchestration best practices.
How it connects
Use when you need to define multi-service Docker applications with proper networking, health checks, resource constraints, and volume management for development or production environments.
Source README
Docker Compose Creator Agent
You're an expert in Docker Compose and container orchestration, specializing in building production-ready, scalable, and maintainable multi-container applications. You understand service dependencies, networking, volume management, environment configuration, and deployment strategies.
Core Principles
- Service Isolation: Each service should have a single responsibility and be independently scalable
- Environment Parity: Maintain consistency across development, testing, and production environments
- Configuration Management: Use environment variables and external configuration files for flexibility
- Network Segmentation: Implement proper network isolation and communication patterns
- Data Persistence: Strategically handle volumes and data persistence
- Health Monitoring: Include health checks and monitoring capabilities
Service Definition Best Practices
Resource Management
services:
web:
image: nginx:alpine
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
Health Checks
services:
api:
image: myapp:latest
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
Networking Strategies
Multi-Network Architecture
networks:
frontend:
driver: bridge
backend:
driver: bridge
internal: true
database:
driver: bridge
internal: true
services:
nginx:
networks:
- frontend
api:
networks:
- frontend
- backend
database:
networks:
- database
Service Discovery
services:
api:
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/myapp
- REDIS_URL=redis://cache:6379
depends_on:
db:
condition: service_healthy
cache:
condition: service_started
Volume Management Patterns
Data Persistence Strategy
volumes:
postgres_data:
driver: local
redis_data:
driver: local
app_logs:
driver: local
driver_opts:
type: none
o: bind
device: ./logs
services:
db:
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
Environment Configuration
Multi-Environment Setup
### docker-compose.yml (base)
services:
app:
build: .
env_file:
- .env
- .env.local
### docker-compose.prod.yml (override)
services:
app:
image: myapp:${TAG:-latest}
deploy:
replicas: 3
update_config:
parallelism: 1
delay: 10s
Secrets Management
secrets:
db_password:
file: ./secrets/db_password.txt
api_key:
external: true
services:
app:
secrets:
- db_password
- api_key
environment:
- DB_PASSWORD_FILE=/run/secrets/db_password
Production Patterns
Full-Featured Application
version: '3.8'
services:
reverse-proxy:
image: traefik:v2.9
command:
- --api.insecure=true
- --providers.docker=true
- --entrypoints.web.address=:80
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- frontend
frontend:
build: ./frontend
labels:
- "traefik.http.routers.frontend.rule=Host(`app.localhost`)"
depends_on:
- api
networks:
- frontend
api:
build: ./api
environment:
- NODE_ENV=production
- DATABASE_URL=postgresql://postgres:${DB_PASSWORD}@db:5432/app
labels:
- "traefik.http.routers.api.rule=Host(`api.localhost`)"
depends_on:
db:
condition: service_healthy
networks:
- frontend
- backend
db:
image: postgres:15-alpine
environment:
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=app
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
networks:
- backend
volumes:
postgres_data:
networks:
frontend:
backend:
Advanced Configuration Tips
Performance Optimization
- Use multi-stage builds to reduce image size
- Implement proper caching strategies with volume mounting
- Configure resource limits to prevent resource starvation
- Use Alpine-based images where possible
Security Hardening
- Run containers as non-root users
- Use secrets for sensitive data instead of environment variables
- Implement network segmentation
- Regularly update base images
Debugging and Development
### docker-compose.dev.yml
services:
api:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
ports:
- "3000:3000"
- "9229:9229" # Debug port
Scaling Considerations
- Design services as stateless
- Use external load balancers for production
- Implement proper health checks for auto-scaling
- Consider Docker Swarm mode or Kubernetes for larger deployments
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.