Docker Compose Deployment
Deploy CoAI.Dev using Docker Compose for development and production environments
Docker Compose Deployment
Docker Compose provides the easiest way to deploy CoAI.Dev with all its dependencies in a single, reproducible setup. This method is perfect for development, testing, and small to medium production deployments.
Overview
Docker Compose deployment includes:
- CoAI.Dev Application: Main application server
- MySQL Database: Data persistence and user management
- Redis Cache: Session storage and performance optimization
- Volume Mounts: Persistent data storage
- Network Configuration: Service communication
Quick Start
The Docker Compose setup gets you running in under 5 minutes with a single command. All services are pre-configured and ready to use.
Prerequisites
Before starting, ensure you have:
- Docker: Version 20.10 or later
- Docker Compose: Version 2.0 or later
- System Resources: Minimum 2GB RAM, 10GB disk space
- Network Access: Internet connection for image downloads
Quick Deployment
Start Services
This command will:
- Download required Docker images
- Create and start all services
- Set up networking between containers
- Initialize the database
Configuration Options
Environment Variables
The Docker Compose setup supports various environment variables:
Security Note: Change default passwords in production deployments.
Volume Mounts
The default setup includes persistent storage:
Production Configuration
Environment-Specific Compose Files
Create docker-compose.dev.yml
:
Usage: docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
Load Balancer Configuration
For production deployments with multiple instances:
Version Management
Stable vs Latest Versions
Version Selection
- latest: Contains the newest features but may have bugs
- stable: Thoroughly tested, recommended for production
- specific tags: Pin to exact versions for consistency
Update Process
Automated Updates
Enable automatic updates with Watchtower:
Deploy with: docker-compose -f docker-compose.yml -f docker-compose.watch.yml up -d
Monitoring and Logging
Container Health Checks
Add health checks to your services:
Log Configuration
Configure centralized logging:
Troubleshooting
Common Issues
Database Connection Failed
Problem: CoAI.Dev cannot connect to MySQL
Solutions:
- Check if MySQL container is running:
docker-compose ps mysql
- Verify database credentials in environment variables
- Check network connectivity:
docker-compose exec chatnio ping mysql
- Review MySQL logs:
docker-compose logs mysql
Port Conflicts
Problem: Port already in use error
Solutions:
- Change the host port in docker-compose.yml
- Stop conflicting services
- Use different port mapping:
"8001:8094"
Performance Issues
Slow Response Times:
- Increase container memory limits
- Check disk I/O performance
- Monitor database queries
- Review network latency
High Resource Usage:
- Implement resource limits in docker-compose.yml
- Monitor container metrics
- Optimize application configuration
- Consider scaling to multiple instances
Debugging Commands
Useful commands for troubleshooting:
Security Best Practices
Production Security
- Change Default Passwords: Update all default credentials
- Use Environment Files: Store secrets in
.env
files - Network Isolation: Use custom Docker networks
- Regular Updates: Keep images and dependencies updated
- Backup Strategy: Implement automated backups
- SSL/TLS: Enable HTTPS for production deployments
Environment File Example
Create .env
file for sensitive data:
Reference in docker-compose.yml:
Docker Compose deployment provides a solid foundation for CoAI.Dev. For larger deployments, consider Kubernetes or explore High Availability configurations.