This guide explains how to deploy SpectrumAlert using Docker for easy deployment anywhere.
-
Docker and Docker Compose
# Install Docker (Ubuntu/Debian) sudo apt update sudo apt install docker.io docker-compose # Add user to docker group sudo usermod -aG docker $USER # Log out and log back in
-
RTL-SDR Device
- Connect your RTL-SDR USB device
- Verify detection:
lsusb | grep -i realtek
-
USB Permissions
# Add user to plugdev group sudo usermod -aG plugdev $USER # Log out and log back in
If you encounter Docker Compose issues (common on Raspberry Pi), use the simplified script:
chmod +x run_docker.sh troubleshoot.sh
./troubleshoot.sh # Check system compatibility
./run_docker.sh build
./run_docker.sh interactivechmod +x deploy.sh
./deploy.sh build./deploy.sh interactiveUse interactive mode to:
- Collect initial RF data
- Train ML models
- Test system functionality
./deploy.sh serviceService mode runs continuously in the background, monitoring spectrum and alerting on anomalies.
./deploy.sh autonomousNEW! Autonomous mode provides complete automation:
- Collects RF data for 24 hours automatically
- Trains ML models on collected data
- Starts continuous anomaly monitoring
- Periodically retrains models (weekly by default)
This is perfect for "set it and forget it" deployments!
Best for initial setup, training, and manual operations:
docker-compose up spectrumalertFeatures:
- Full menu interface
- Data collection
- Model training
- Manual monitoring
- System diagnostics
NEW! Fully automated end-to-end workflow:
docker-compose --profile autonomous up -d spectrumalert-autonomousFeatures:
- Automatic 24-hour data collection
- Automatic model training
- Continuous monitoring
- Periodic retraining (weekly)
- Zero human intervention required
- Comprehensive status logging
Best for production deployment with continuous monitoring:
docker-compose --profile service up -d spectrumalert-serviceFeatures:
- Automatic model selection
- Continuous monitoring
- Auto-restart on failures
- Background operation
- Status logging
Copy and modify the environment file:
cp .env.example .env
# Edit .env with your settingsKey variables:
COLLECTION_HOURS: Hours of data to collect initially (default: 24)RETRAIN_INTERVAL_HOURS: Hours between automatic retraining (default: 168 = weekly)MIN_TRAINING_SAMPLES: Minimum samples required for training (default: 1000)SERVICE_MODEL: Model to use (latestor specific filename)SERVICE_LITE_MODE: Use lite mode for resource-constrained systemsSERVICE_ALERT_THRESHOLD: Anomaly detection threshold (0.0-1.0)LOG_LEVEL: Logging verbosity (DEBUG,INFO,WARNING,ERROR)
Data is persisted in these directories:
./data/: RF data files./models/: Trained ML models./logs/: Application logs./config/: Configuration files
./deploy.sh build # Build Docker image
./deploy.sh interactive # Run interactive mode
./deploy.sh autonomous # Run autonomous mode (recommended)
./deploy.sh service # Run service mode./deploy.sh status # Show container status
./deploy.sh logs # Show container logs
./deploy.sh stop # Stop all containers./deploy.sh shell # Open shell in container
./deploy.sh clean # Remove all containers and imagesFor systems where Docker Compose has issues, use these alternative scripts:
./run_docker.sh build # Build image
./run_docker.sh interactive # Interactive mode
./run_docker.sh autonomous # Autonomous mode (24h + training)
./run_docker.sh service # Service mode
./run_docker.sh status # Check status
./run_docker.sh logs # View logs
./run_docker.sh stop # Stop containers./troubleshoot.sh # Diagnose Docker/RTL-SDR issuesdocker-compose upRuns interactive mode with full menu interface.
docker-compose --profile service up -dRuns continuous monitoring service in background.
docker-compose --profile web up -dRuns web dashboard interface (planned feature).
If you get Not supported URL scheme http+docker error:
- Run the troubleshooting script:
./troubleshoot.sh - Use the simple runner instead:
./run_docker.sh build && ./run_docker.sh interactive - For service mode:
./run_docker.sh service
- Check USB connection:
lsusb | grep -i realtek - Check permissions:
groups | grep plugdev - Restart container:
./deploy.sh stop && ./deploy.sh service
- Run interactive mode first:
./deploy.sh interactive - Collect data (menu option 1)
- Train models (menu option 2)
- Exit and start service mode
- Check logs:
./deploy.sh logs - Verify USB access:
docker run --rm --device=/dev/bus/usb:/dev/bus/usb spectrumalert:latest lsusb - Check disk space:
df -h
- Check service logs:
./deploy.sh logs spectrumalert-service - Verify models exist:
ls -la models/ - Check RTL-SDR stability: May need USB hub with power supply
Create /etc/systemd/system/spectrumalert.service:
[Unit]
Description=SpectrumAlert RF Monitoring
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/spectrumalert
ExecStart=/opt/spectrumalert/deploy.sh service
ExecStop=/opt/spectrumalert/deploy.sh stop
TimeoutStartSec=0
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl enable spectrumalert
sudo systemctl start spectrumalertAdd to docker-compose.yml:
restart: unless-stoppedConfigure in /etc/logrotate.d/spectrumalert:
/opt/spectrumalert/logs/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 644 1000 1000
}
-
Container Security
- Runs as non-root user (spectrum:1000)
- Minimal base image (python:3.11-slim)
- No unnecessary packages
-
Device Access
- Uses
--devicemount (preferred over--privileged) - Limited to USB bus access only
- Uses
-
Network Security
- Uses host networking for RTL-SDR access
- No exposed ports by default
- MQTT credentials in environment file
Add to docker-compose.yml:
deploy:
resources:
limits:
memory: 1G
cpus: '2.0'
reservations:
memory: 512M
cpus: '1.0'For high sample rates, consider:
- Dedicated USB 3.0 port
- Powered USB hub
- USB buffer size tuning
Built-in health check verifies RTL-SDR access every 30 seconds.
Check service status file:
cat logs/service_status.jsonMonitor logs for alerts:
tail -f logs/service.log | grep -i "anomaly\|alert"tar -czf models-backup-$(date +%Y%m%d).tar.gz models/tar -czf config-backup-$(date +%Y%m%d).tar.gz config/ .envtar -xzf models-backup-YYYYMMDD.tar.gz
tar -xzf config-backup-YYYYMMDD.tar.gz