CoAI LogoCoAI.Dev

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

Clone Repository

git clone --depth=1 --branch=main --single-branch https://github.com/coaidev/coai.git
cd chatnio

Start Services

docker-compose up -d

This command will:

  • Download required Docker images
  • Create and start all services
  • Set up networking between containers
  • Initialize the database

Verify Deployment

Check that all services are running:

docker-compose ps

Access CoAI.Dev at http://localhost:8000

Configuration Options

Environment Variables

The Docker Compose setup supports various environment variables:

# MySQL Configuration
MYSQL_HOST: mysql
MYSQL_PORT: 3306
MYSQL_DB: chatnio
MYSQL_USER: root
MYSQL_PASSWORD: chatnio123456
 
# Redis Configuration
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ""

Security Note: Change default passwords in production deployments.

Volume Mounts

The default setup includes persistent storage:

volumes:
  # Configuration files
  - ./config:/config
  
  # Application logs
  - ./logs:/logs
  
  # File uploads and storage
  - ./storage:/storage
  
  # Database data
  - ./db:/var/lib/mysql
  
  # Redis data
  - ./redis:/data

Production Configuration

Environment-Specific Compose Files

Create docker-compose.dev.yml:

version: '3.8'
services:
  chatnio:
    environment:
      - DEBUG=true
      - LOG_LEVEL=debug
      - AUTO_RELOAD=true
    ports:
      - "8000:8094"
      - "9229:9229"  # Debug port
    volumes:
      - .:/app
      - /app/node_modules

Usage: docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d

Load Balancer Configuration

For production deployments with multiple instances:

version: '3.8'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - chatnio-1
      - chatnio-2
      - chatnio-3
 
  chatnio-1:
    image: programzmh/chatnio:stable
    environment:
      - INSTANCE_ID=1
 
  chatnio-2:
    image: programzmh/chatnio:stable
    environment:
      - INSTANCE_ID=2
 
  chatnio-3:
    image: programzmh/chatnio:stable
    environment:
      - INSTANCE_ID=3

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

Backup Data

# Stop services
docker-compose down
 
# Backup database
docker run --rm -v $(pwd)/db:/var/lib/mysql \
  -v $(pwd)/backup:/backup mysql:8.0 \
  mysqldump -h mysql -u root -p chatnio > /backup/chatnio_backup.sql

Update Images

# Pull latest images
docker-compose pull
 
# Restart services
docker-compose up -d

Verify Update

Check application logs and functionality:

docker-compose logs -f chatnio

Automated Updates

Enable automatic updates with Watchtower:

version: '3.8'
services:
  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - WATCHTOWER_POLL_INTERVAL=300
      - WATCHTOWER_CLEANUP=true
    command: chatnio mysql redis

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:

services:
  chatnio:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8094/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
 
  mysql:
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 30s
      timeout: 10s
      retries: 3

Log Configuration

Configure centralized logging:

services:
  chatnio:
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
        
  # Optional: Add log aggregation
  fluentd:
    image: fluentd:v1.14-1
    volumes:
      - ./fluentd:/fluentd/etc
    ports:
      - "24224:24224"

Troubleshooting

Common Issues

Database Connection Failed

Problem: CoAI.Dev cannot connect to MySQL

Solutions:

  1. Check if MySQL container is running: docker-compose ps mysql
  2. Verify database credentials in environment variables
  3. Check network connectivity: docker-compose exec chatnio ping mysql
  4. Review MySQL logs: docker-compose logs mysql

Port Conflicts

Problem: Port already in use error

Solutions:

  1. Change the host port in docker-compose.yml
  2. Stop conflicting services
  3. 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:

# View all container status
docker-compose ps
 
# Check container logs
docker-compose logs -f [service_name]
 
# Execute commands in containers
docker-compose exec chatnio bash
docker-compose exec mysql mysql -u root -p
 
# View resource usage
docker stats
 
# Inspect networks
docker network ls
docker network inspect chatnio_default

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:

# Database Credentials
MYSQL_ROOT_PASSWORD=your_secure_password_here
MYSQL_PASSWORD=your_app_password_here
 
# Application Secrets
JWT_SECRET=your_jwt_secret_key_here
API_SECRET=your_api_secret_here
 
# External Service Keys
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here

Reference in docker-compose.yml:

environment:
  - MYSQL_PASSWORD=${MYSQL_PASSWORD}
  - JWT_SECRET=${JWT_SECRET}

Docker Compose deployment provides a solid foundation for CoAI.Dev. For larger deployments, consider Kubernetes or explore High Availability configurations.