This guide documents the Docker infrastructure prepared for DAFU. All services are currently commented out in docker-compose.yml until ML model integration with the API is complete.
What Works Now:
- ML Models (Isolation Forest, LSTM/GRU) via direct Python execution
- Model training, prediction, and persistence
- All fraud detection capabilities work without Docker
Docker Status:
- ✅ Configuration files ready
- ✅ Database schemas prepared
- ✅ Service definitions complete
⚠️ Services commented out until API-ML integration
- Quick Start
- Prerequisites
- Installation
- Configuration
- Services Overview
- Usage
- Monitoring
- Troubleshooting
- Production Deployment
# 1. Clone the repository
git clone https://github.com/MasterFabric/dafu.git
cd dafu/fraud_detection
# 2. Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Run ML models
cd src/models
python main.py # Interactive model selection# Uncomment services in docker-compose.yml first
docker-compose up -dCurrent Status: Infrastructure ready, integration pending 🔄
- Docker: Version 20.10+ (Install Docker)
- Docker Compose: Version 2.0+ (Install Compose)
- Git: For cloning the repository
Minimum:
- 4 GB RAM
- 2 CPU cores
- 10 GB free disk space
Recommended:
- 8 GB RAM
- 4 CPU cores
- 20 GB free disk space
Production:
- 16+ GB RAM
- 8+ CPU cores
- 50+ GB free disk space
- SSD storage for databases
# Check Docker version
docker --version
# Expected: Docker version 20.10.0 or higher
# Check Docker Compose version
docker-compose --version
# Expected: Docker Compose version 2.0.0 or higher
# Test Docker
docker run hello-worldgit clone https://github.com/MasterFabric/dafu.git
cd dafu# Copy example environment file
cp .env.example .env
# Edit configuration (optional)
nano .envImportant: Update the following values in .env for production:
SECRET_KEY- Change to a secure random stringPOSTGRES_PASSWORD- Use a strong passwordRABBITMQ_PASSWORD- Use a strong passwordGRAFANA_PASSWORD- Change default password- All other default passwords
# Build and start all services
docker-compose up -d
# Expected output:
# Creating network "dafu-network" ... done
# Creating volume "dafu-postgres-data" ... done
# Creating volume "dafu-redis-data" ... done
# Creating dafu-postgres ... done
# Creating dafu-redis ... done
# Creating dafu-rabbitmq ... done
# Creating dafu-fraud-api ... done
# Creating dafu-celery-worker ... done
# Creating dafu-prometheus ... done
# Creating dafu-grafana ... done# Check service status
docker-compose ps
# Expected output:
# NAME STATUS PORTS
# dafu-fraud-api Up (healthy) 0.0.0.0:8000->8000/tcp
# dafu-postgres Up (healthy) 0.0.0.0:5432->5432/tcp
# dafu-redis Up (healthy) 0.0.0.0:6379->6379/tcp
# dafu-rabbitmq Up 0.0.0.0:5672->5672/tcp, 0.0.0.0:15672->15672/tcp
# dafu-celery-worker Up
# dafu-prometheus Up 0.0.0.0:9090->9090/tcp
# dafu-grafana Up 0.0.0.0:3000->3000/tcpOpen your browser and navigate to:
- API Documentation: http://localhost:8000/docs
- Grafana Dashboards: http://localhost:3000 (admin/admin)
- Prometheus Metrics: http://localhost:9090
- RabbitMQ Management: http://localhost:15672 (dafu/dafu_rabbitmq_password)
The .env file contains all configuration options:
FRAUD_DETECTION_ENV=development # development | staging | production
LOG_LEVEL=INFO # DEBUG | INFO | WARNING | ERROR
API_WORKERS=4 # Number of API workersPOSTGRES_USER=dafu
POSTGRES_PASSWORD=dafu_secure_password # CHANGE IN PRODUCTION!
POSTGRES_DB=dafu
POSTGRES_PORT=5432REDIS_PORT=6379
REDIS_PASSWORD= # Leave empty for no passwordRABBITMQ_USER=dafu
RABBITMQ_PASSWORD=dafu_rabbitmq_password # CHANGE IN PRODUCTION!
RABBITMQ_PORT=5672
RABBITMQ_MANAGEMENT_PORT=15672PROMETHEUS_PORT=9090
GRAFANA_PORT=3000
GRAFANA_USER=admin
GRAFANA_PASSWORD=admin # CHANGE IN PRODUCTION!To modify service configuration:
- API Configuration: Edit
core/features/fraud_detection/src/api/main.py - Database Schema: Edit
core/features/fraud_detection/deployment/init-db.sql - Prometheus: Edit
core/features/fraud_detection/deployment/prometheus.yml - Grafana: Edit
core/features/fraud_detection/deployment/grafana-datasources.yml
After changes, rebuild and restart:
docker-compose down
docker-compose up -d --buildMain application service providing fraud detection capabilities.
- Port: 8000
- Technology: FastAPI, Python 3.9
- Features:
- Real-time fraud scoring
- Batch processing
- Model management
- RESTful API with OpenAPI documentation
Endpoints:
GET /- Service informationGET /health- Health checkPOST /api/v1/score- Real-time fraud scoringPOST /api/v1/batch/analyze- Batch analysisGET /api/v1/models- List modelsGET /docs- Interactive API documentation
Persistent data storage.
- Port: 5432
- Version: PostgreSQL 15 Alpine
- Database: dafu
- Features:
- Transaction storage
- User and merchant data
- Model metadata
- Fraud predictions history
In-memory data store and cache.
- Port: 6379
- Version: Redis 7 Alpine
- Features:
- Prediction caching
- Session storage
- Rate limiting
- Real-time data
Message queue for asynchronous processing.
- Ports: 5672 (AMQP), 15672 (Management UI)
- Version: RabbitMQ 3.12 Management Alpine
- Features:
- Task queue for Celery workers
- Event-driven architecture
- Reliable message delivery
Background task processor.
- Technology: Celery with Python
- Features:
- Batch processing jobs
- Model training tasks
- Scheduled jobs
- Report generation
Metrics collection and monitoring.
- Port: 9090
- Features:
- Application metrics
- Service health monitoring
- Custom metrics
- Alerting rules
Metrics visualization and dashboards.
- Port: 3000
- Default Login: admin / admin
- Features:
- Real-time dashboards
- Custom visualizations
- Alerting
- Data source integration
# Start all services
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# View logs for specific service
docker-compose logs -f fraud-detection-api
# Restart a service
docker-compose restart fraud-detection-api
# Rebuild and restart
docker-compose up -d --build
# Remove all containers and volumes
docker-compose down -v# Start only API and dependencies
docker-compose up -d postgres redis rabbitmq fraud-detection-api
# Stop Grafana
docker-compose stop grafana
# Restart Redis
docker-compose restart redis# Scale API to 3 instances
docker-compose up -d --scale fraud-detection-api=3
# Scale Celery workers to 5 instances
docker-compose up -d --scale celery-worker=5Start additional management tools:
# Start PgAdmin and Redis Commander
docker-compose --profile tools up -d
# Access PgAdmin: http://localhost:5050
# Access Redis Commander: http://localhost:8081curl http://localhost:8000/healthcurl -X POST http://localhost:8000/api/v1/score \
-H "Content-Type: application/json" \
-d '{
"transaction_id": "tx_123",
"amount": 150.00,
"user_id": "user_456",
"merchant_id": "merchant_789",
"timestamp": "2024-01-15T10:30:00Z",
"device_fingerprint": "fp_abc123",
"ip_address": "192.168.1.1"
}'curl http://localhost:8000/api/v1/models-
Grafana Dashboards
open http://localhost:3000 # Login: admin / admin -
Prometheus Metrics
open http://localhost:9090
-
RabbitMQ Management
open http://localhost:15672 # Login: dafu / dafu_rabbitmq_password
# All services
docker-compose logs -f
# API only
docker-compose logs -f fraud-detection-api
# Last 100 lines
docker-compose logs --tail=100 fraud-detection-api
# Follow logs from specific time
docker-compose logs --since="2024-01-15T10:00:00" fraud-detection-api# API health
curl http://localhost:8000/health
# Database connection
docker-compose exec postgres pg_isready -U dafu
# Redis connection
docker-compose exec redis redis-cli ping# View resource usage
docker stats
# Service-specific stats
docker stats dafu-fraud-apiError:
Error starting userland proxy: listen tcp 0.0.0.0:8000: bind: address already in use
Solution:
# Find process using port
lsof -i :8000
# Kill process
kill -9 <PID>
# Or change port in .env
echo "API_PORT=8001" >> .env
docker-compose up -dError:
could not connect to server: Connection refused
Solution:
# Check database status
docker-compose ps postgres
# Restart database
docker-compose restart postgres
# Check logs
docker-compose logs postgres
# Verify database is initialized
docker-compose exec postgres psql -U dafu -d dafu -c "\dt"Error:
Cannot allocate memory
Solution:
# Increase Docker memory in Docker Desktop settings
# Or reduce workers in .env
echo "API_WORKERS=2" >> .env
echo "MAX_WORKERS=2" >> .env
docker-compose up -d --buildError:
Permission denied: '/app/models'
Solution:
# Fix permissions
chmod -R 755 core/features/fraud_detection/models
chmod -R 755 core/features/fraud_detection/results
# Restart services
docker-compose restartSolution:
# View detailed logs
docker-compose logs fraud-detection-api
# Rebuild container
docker-compose build --no-cache fraud-detection-api
docker-compose up -d
# Remove and recreate
docker-compose down
docker-compose up -dIf all else fails, perform a clean reset:
# Stop all services
docker-compose down
# Remove volumes (WARNING: deletes all data!)
docker-compose down -v
# Remove all images
docker-compose down --rmi all
# Clean Docker system
docker system prune -a --volumes
# Rebuild from scratch
docker-compose up -d --build# Check service status
docker-compose ps
# View service logs
docker-compose logs
# Enter container shell
docker-compose exec fraud-detection-api bash
# Check environment variables
docker-compose exec fraud-detection-api env- Update all passwords in
.env - Set
FRAUD_DETECTION_ENV=production - Enable API key authentication
- Configure SSL/TLS certificates
- Set up backup strategy
- Configure monitoring alerts
- Review security settings
- Test disaster recovery
- Document runbooks
# .env production settings
FRAUD_DETECTION_ENV=production
LOG_LEVEL=WARNING
DEBUG=false
API_KEY_ENABLED=true
ENABLE_RATE_LIMITING=true
# Strong passwords
SECRET_KEY=<generate-32-char-random-string>
POSTGRES_PASSWORD=<strong-password>
RABBITMQ_PASSWORD=<strong-password>
REDIS_PASSWORD=<strong-password>-
Enable TLS/SSL
# Use reverse proxy (nginx/traefik) with SSL # Configure HTTPS in docker-compose.yml
-
Restrict Network Access
# Remove port exposures for internal services # Use firewall rules
-
Enable Authentication
# Set API_KEY_ENABLED=true # Configure OAuth2/JWT
-
Regular Updates
# Update base images docker-compose pull docker-compose up -d
# Backup PostgreSQL
docker-compose exec postgres pg_dump -U dafu dafu > backup.sql
# Backup Redis
docker-compose exec redis redis-cli SAVE
# Backup models
tar -czf models-backup.tar.gz core/features/fraud_detection/models/
# Restore PostgreSQL
docker-compose exec -T postgres psql -U dafu dafu < backup.sqlConfigure alerts in Prometheus:
# Example alert rule
groups:
- name: fraud_detection
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.05
annotations:
summary: High error rate detected# Scale API instances
docker-compose up -d --scale fraud-detection-api=5
# Scale Celery workers
docker-compose up -d --scale celery-worker=10
# Use load balancer (nginx, traefik)- FastAPI Documentation
- Docker Documentation
- PostgreSQL Documentation
- Redis Documentation
- RabbitMQ Documentation
- Prometheus Documentation
- Grafana Documentation
- GitHub Repository: https://github.com/MasterFabric/dafu
- Issue Tracker: https://github.com/MasterFabric/dafu/issues
- Main README: ../README.md
- Email: dafu@masterfabric.co
- Issues: GitHub Issues
- License: AGPL-3.0
Your DAFU Enterprise Fraud Detection Platform is now running with Docker!
Next Steps:
- Explore API documentation: http://localhost:8000/docs
- View Grafana dashboards: http://localhost:3000
- Test fraud detection with sample data
- Customize models and configuration
- Deploy to production
Happy Fraud Detecting! 🚀
DAFU - Enterprise Fraud Detection & E-commerce Analytics Platform
Built with ❤️ by MasterFabric