Docker Deployment Guide

Complete Docker setup for the Enterprise AI Chatbot Platform with optimized production builds and development environment.

Quick Start: Use the provided scripts for fastest deployment. Development environment includes hot reload, while production is optimized for performance.

Quick Start

1 Clone the Repository

git clone https://github.com/Penguin-International-Gurgaon/ai-chatbot-entrpise-kit.git
cd ai-chatbot-entrpise-kit

2 Development Environment

# Start development environment with hot reload
./scripts/start-dev.sh

# Or manually
docker-compose -f docker-compose.dev.yml up --build

3 Production Environment

# Copy and configure environment
cp .env.docker.example .env
# Edit .env with your configuration

# Start production environment
./scripts/start-prod.sh

# Or manually
docker-compose -f docker-compose.prod.yml up --build -d

File Structure

├── Dockerfile                 # Optimized production image
├── Dockerfile.dev            # Development image with hot reload
├── docker-compose.dev.yml    # Development environment
├── docker-compose.prod.yml   # Production environment
├── .dockerignore             # Docker ignore rules
├── .env.docker.example       # Environment template
├── nginx/
│   └── nginx.conf            # Nginx reverse proxy config
└── scripts/
    ├── start-dev.sh          # Development startup script
    ├── start-prod.sh         # Production startup script
    ├── backup-db.sh          # Database backup script
    └── init-db.sql           # Database initialization

Docker Images

Production Image

  • Base: Node.js 18 Alpine
  • Size: ~200MB (optimized)
  • Multi-stage build
  • Standalone Next.js output
  • Non-root user for security
  • Health checks included

Development Image

  • Base: Node.js 18 Alpine
  • Size: ~500MB (includes dev deps)
  • Hot reload support
  • Volume mounting
  • Debugging support
  • Development tools included

Environment Configuration

Development (.env.local)

NODE_ENV=development
DATABASE_URL=postgresql://postgres:password@localhost:5432/ai_chatbot_dev
AUTH_SECRET=dev-secret-key
NEXTAUTH_URL=http://localhost:3000
OPENAI_API_KEY=your-key-here
ADMIN_EMAIL=admin@example.com

Production (.env)

NODE_ENV=production
POSTGRES_PASSWORD=secure_password_here
DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/ai_chatbot_prod
AUTH_SECRET=super-secure-secret-key
NEXTAUTH_URL=https://your-domain.com
OPENAI_API_KEY=your-production-key
ANTHROPIC_API_KEY=your-anthropic-key
ADMIN_EMAIL=admin@your-domain.com

Services

App Service

  • Ports: 3000 (internal), 3000 (host)
  • Health check: /api/health endpoint
  • Dependencies: Database, Redis (optional)
  • Restart: unless-stopped

PostgreSQL Database

  • Image: postgres:15-alpine
  • Ports: 5432
  • Health check: pg_isready command
  • Volumes: Persistent data storage
  • Backup: Located in ./backups/

Redis (Optional)

  • Image: redis:7-alpine
  • Purpose: Session storage, caching
  • Health check: redis-cli ping
  • Security: Password protected in production

Nginx Reverse Proxy

  • Ports: 80, 443
  • Rate limiting (API: 10 req/s)
  • Gzip compression
  • Security headers
  • SSL/TLS termination ready

Common Commands

Development

# Start development environment
./scripts/start-dev.sh

# View logs
docker-compose -f docker-compose.dev.yml logs -f

# Access app container
docker-compose -f docker-compose.dev.yml exec app sh

# Run database migrations
docker-compose -f docker-compose.dev.yml exec app pnpm db:migrate

# Stop environment
docker-compose -f docker-compose.dev.yml down

Production

# Start production environment
./scripts/start-prod.sh

# View logs
docker-compose -f docker-compose.prod.yml logs -f

# Create database backup
./scripts/backup-db.sh

# Update and rebuild
docker-compose -f docker-compose.prod.yml pull
docker-compose -f docker-compose.prod.yml up --build -d

Health Checks & Monitoring

Health Check Endpoints:
  • App Health: http://localhost:3000/api/health
  • Nginx Status: http://localhost:80/health

Health Check Response

{
  "status": "ok",
  "timestamp": "2024-01-01T00:00:00.000Z",
  "uptime": 3600,
  "environment": "production",
  "version": "3.0.6"
}

Troubleshooting

Common Issues:
  • Container won't start: Check logs with docker-compose logs app
  • Database connection issues: Verify database is running with docker-compose ps db
  • Port conflicts: Check for processes using ports with lsof -i :3000

Debug Commands

# Check container health
docker-compose -f docker-compose.prod.yml ps

# View health check logs
docker inspect --format='{{json .State.Health}}' container_name

# Check resource usage
docker stats

# Test database connection
docker-compose -f docker-compose.prod.yml exec db pg_isready -U postgres

Production Deployment Checklist

Deployment Complete! Your Enterprise AI Chatbot Platform is now running in Docker. Monitor the health endpoints and check logs for any issues.