π³ HΖ°α»ng dαΊ«n Deploy UIP vα»i Docker
Β· 4 min read
HΖ°α»ng dαΊ«n chi tiαΊΏt cΓ‘ch deploy toΓ n bα» UIP stack sα» dα»₯ng Docker vΓ Docker Compose. BΓ i viαΊΏt nΓ y sαΊ½ Δi qua tα»«ng bΖ°α»c tα»« setup mΓ΄i trΖ°α»ng ΔαΊΏn monitoring.
π Prerequisitesβ
TrΖ°α»c khi bαΊ―t ΔαΊ§u, ΔαΊ£m bαΊ£o bαΊ‘n cΓ³:
| Requirement | Minimum | Recommended |
|---|---|---|
| Docker | 20.10+ | 24.0+ |
| Docker Compose | 2.0+ | 2.20+ |
| RAM | 8GB | 16GB |
| Storage | 50GB | 100GB SSD |
| CPU | 4 cores | 8 cores |
CΓ i ΔαΊ·t Docker (nαΊΏu chΖ°a cΓ³)β
# Ubuntu/Debian
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# Verify installation
docker --version
docker compose version
ποΈ Architecture Overviewβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Docker Network β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β Frontendβ β Backend β β MongoDB β β Redis β β
β β :3000 β β :8000 β β :27017 β β :6379 β β
β ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ β
β β β β β β
β βββββββββββββ΄βββββββββββββ΄βββββββββββββ β
β β β
β βββββββββββ ββββββββββ΄βββββββ βββββββββββ β
β β Stellio β β Fuseki β β Grafana β β
β β :8080 β β :3030 β β :3001 β β
β βββββββββββ βββββββββββββββββ βββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Quick Startβ
1. Clone Repositoryβ
git clone https://github.com/UIP-Urban-Intelligence-Platform/UIP-Urban_Intelligence_Platform.git
cd UIP-Urban_Intelligence_Platform
2. Environment Setupβ
# Copy example environment file
cp .env.example .env
# Edit configuration
nano .env
CΓ‘c biαΊΏn mΓ΄i trΖ°α»ng quan trα»ng:
# Application
APP_ENV=production
APP_DEBUG=false
# MongoDB
MONGODB_HOST=mongodb
MONGODB_PORT=27017
MONGODB_DATABASE=uip
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
# Stellio (NGSI-LD Context Broker)
STELLIO_URL=http://stellio:8080
# Fuseki (RDF Triple Store)
FUSEKI_URL=http://fuseki:3030
# API Keys (optional)
CAMERA_API_KEY=your_camera_api_key
3. Build vΓ Startβ
# Build all images
docker compose build
# Start all services
docker compose up -d
# Check status
docker compose ps
4. Verify Servicesβ
# Check all containers are running
docker compose ps
# View logs
docker compose logs -f
# Test API endpoint
curl http://localhost:8000/health
π¦ Docker Compose Servicesβ
docker-compose.yml breakdownβ
version: "3.8"
services:
# Frontend - React Dashboard
frontend:
build:
context: ./apps/traffic-web-app/frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- REACT_APP_API_URL=http://localhost:8000
depends_on:
- backend
# Backend - FastAPI Server
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
environment:
- MONGODB_URL=mongodb://mongodb:27017
- REDIS_URL=redis://redis:6379
depends_on:
- mongodb
- redis
volumes:
- ./data:/app/data
- ./logs:/app/logs
# MongoDB - Primary Database
mongodb:
image: mongo:6
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
healthcheck:
test: mongosh --eval 'db.runCommand("ping").ok'
interval: 10s
timeout: 5s
retries: 5
# Redis - Caching & Message Queue
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: redis-server --appendonly yes
# Stellio - NGSI-LD Context Broker
stellio:
image: stellio/stellio-context-broker:latest
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- postgres
- kafka
# Fuseki - RDF Triple Store
fuseki:
image: stain/jena-fuseki
ports:
- "3030:3030"
volumes:
- fuseki_data:/fuseki
environment:
- ADMIN_PASSWORD=admin
volumes:
mongodb_data:
redis_data:
fuseki_data:
π§ Advanced Configurationβ
Production Settingsβ
# docker-compose.prod.yml
services:
backend:
deploy:
replicas: 3
resources:
limits:
cpus: '2'
memory: 4G
restart_policy:
condition: on-failure
max_attempts: 3
GPU Support for YOLOXβ
# docker-compose.gpu.yml
services:
cv-detector:
build:
context: .
dockerfile: Dockerfile.gpu
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
π Monitoringβ
Grafana Dashboardβ
- Access Grafana: http://localhost:3001
- Default credentials: admin/admin
- Import dashboard:
config/grafana_dashboard.json
Health Checksβ
# Check all services
./scripts/health_check.sh
# Output:
# β
Frontend: healthy
# β
Backend: healthy
# β
MongoDB: healthy
# β
Redis: healthy
# β
Stellio: healthy
# β
Fuseki: healthy
π Common Operationsβ
Restart Servicesβ
# Restart all
docker compose restart
# Restart specific service
docker compose restart backend
View Logsβ
# All logs
docker compose logs -f
# Specific service
docker compose logs -f backend
# Last 100 lines
docker compose logs --tail=100 backend
Scale Servicesβ
# Scale backend to 3 instances
docker compose up -d --scale backend=3
Backup Dataβ
# Backup MongoDB
docker exec mongodb mongodump --out /backup
# Backup Fuseki
docker exec fuseki /fuseki/bin/s-copy default backup.nq
π οΈ Troubleshootingβ
Common Issuesβ
| Issue | Solution |
|---|---|
| Port already in use | docker compose down then change ports in .env |
| Out of memory | Increase Docker memory limit |
| Permission denied | Run sudo chmod -R 777 ./data ./logs |
| Container won't start | Check logs with docker compose logs <service> |
Reset Everythingβ
# Stop and remove all containers, volumes, networks
docker compose down -v
# Rebuild from scratch
docker compose build --no-cache
docker compose up -d
π Resourcesβ
CΓ’u hα»i? Mα» issue trΓͺn GitHub
Nguyα» n Viα»t HoΓ ng - Full-Stack Developer @ UIP Team
