This guide describes how to deploy the AI Traffic Management System using Docker and Docker Compose.
Containerized deployment ensures:
- Environment consistency
- Simplified setup
- Isolation of dependencies
- Production-ready scalability
Important
Docker deployment is the recommended method for both development and production environments.
The system runs as two primary containers:
- Production Base Image:
nginx:alpine - Development Base Image:
node:18 - Port Mapping:
- Production →
3000:80 - Development →
3000:3000
- Production →
- Role: Serves the React build and proxies API requests (if configured)
- Hosts static React build (production)
- Supports hot reload (development)
- Connects to backend via internal Docker network
- Base Image:
python:3.10-slim - Port Mapping:
5000:5000
libgl1(required for OpenCV)libgomp1(required for OpenMP / C++ optimization)
Persistent directories:
backend/uploads/backend/outputs/backend/data/
Important
Volume mounting ensures logs, analytics, and uploaded files persist across container restarts.
Download model weights and build Docker images:
make setupThis step:
- Downloads large YOLO weight files
- Builds frontend and backend images
- Prepares required directories
Important
Run this step before make up to avoid build failures.
Starts optimized containers in detached mode:
make upAccess services:
- Frontend → http://localhost:3000
- Backend → http://localhost:5000
Starts containers with volume mounting for hot reload:
make devFeatures:
- Live code updates
- Debug-friendly configuration
- Mounted source directories
Stop and remove running containers:
make downTo remove volumes as well:
docker compose down -vWarning
Removing volumes will delete persisted data.
Environment variables are loaded via .env files inside:
frontend/backend/
| Variable | Description |
|---|---|
FLASK_ENV |
Application mode (development or production) |
MAX_UPLOAD_SIZE_MB |
Maximum allowed upload size (default: 200) |
| Variable | Description |
|---|---|
REACT_APP_API_URL |
Backend API base URL |
Important
All React environment variables must be prefixed with REACT_APP_.
Docker Compose creates an internal bridge network allowing:
- Frontend to communicate with backend using service name
- Isolated inter-container communication
- No need for hardcoded IP addresses
Example internal API URL:
http://backend:5000
- Ensure
make setuphas completed successfully. - Confirm YOLO weight files exist before building images.
- Clear Docker cache if needed:
docker builder pruneIf ports 3000 or 5000 are already in use:
sudo lsof -i :3000
sudo lsof -i :5000Stop conflicting services or modify docker-compose.yml port mappings.
If volume mounting fails:
sudo chown -R $USER:$USER backend/dataEnsure the Docker user has write access to:
backend/databackend/uploadsbackend/outputs
If the system works locally but fails inside Docker:
Check the following:
- Missing system libraries (OpenCV dependencies)
- Incorrect environment variables
- Hardcoded file paths
- Differences in Python version
- Missing model weight files inside container
- Improper volume mounting
To debug inside container:
docker exec -it <container_name> bashInspect logs:
docker logs <container_name>Important
Docker containers are isolated environments. Always verify dependencies are installed inside the image, not just on the host system.
- Use multi-stage Docker builds for smaller images
- Enable Nginx compression (gzip)
- Use a reverse proxy (Nginx / Traefik)
- Add health checks in
docker-compose.yml - Store logs externally for scaling setups
Browser
│
▼
Frontend Container (Nginx)
│
▼
Backend Container (Flask + C++ + YOLO)
│
▼
Volumes (uploads / outputs / analytics)
- Docker Engine 20.10+
- Docker Compose 2.0+
Important
Ensure Docker daemon is running before executing any Makefile commands.