Overview
Docker provides the easiest way to run YOLO-Pi by packaging all dependencies, including OpenCV, TensorFlow, and Keras, into a single container image. YOLO-Pi includes separate Dockerfiles for x86 (laptops/desktops) and ARM (Raspberry Pi) platforms.Architecture Support
| Platform | Dockerfile | Base Image | Build Time |
|---|---|---|---|
| x86/x64 | Dockerfile.x86 | python:3.6 | ~20 minutes |
| ARM (RPi) | Dockerfile.rpi | resin/rpi-raspbian:stretch | Several hours |
Prerequisites
Building for x86/x64
The x86 Dockerfile is optimized for development and testing on laptops and desktops.Review Dockerfile.x86
The x86 Dockerfile includes:
- Python 3.6 base image
- System dependencies (build tools, libraries)
- Python packages: NumPy, Keras 2.1.2, TensorFlow 1.1.0, Pillow 4.3.0, h5py 2.7.1
- OpenCV 3.3.0 compiled from source with optimizations (AVX, OpenGL, OpenCL, TBB, Eigen)
- Kafka-python for messaging (alternative to MQTT)
Run Container
Run with camera access and current directory mounted:Parameters explained:
-it: Interactive terminal--rm: Remove container after exit--privileged: Grant extended privileges (required for camera access)--device=/dev/video0:/dev/video0: Mount camera device-v $(pwd):/app: Mount current directory to/appin container
Building for ARM (Raspberry Pi)
The ARM Dockerfile is specifically configured for Raspberry Pi hardware.Prepare Build Environment
On Raspberry Pi, set up a USB swap drive before building. See the Raspberry Pi setup guide for detailed instructions.
Download TensorFlow Wheel
The ARM build requires a pre-compiled TensorFlow binary:Place
Dockerfile.rpi in the same directory as the wheel file.Build Image (Long Process)
Use Press
screen to maintain your session during the long build:Ctrl+A then D to detach. Reattach later with screen -r.Dockerfile Comparison
Environment Variables
The YOLO-Pi script requires theMQTT environment variable to connect to your MQTT broker.
Setting MQTT Server
.env file:
.env
Volume Mounts
Mount local directories to customize model files or access output:Mount Model Data
Mount Source Code for Development
yolo-pi.py locally and test changes in the container.
Docker Compose
For easier management, create adocker-compose.yml:
docker-compose.yml
Troubleshooting
Permission denied: /dev/video0
Permission denied: /dev/video0
Add your user to the Or run with
video group:--privileged flag (already included in examples).Build fails on Raspberry Pi
Build fails on Raspberry Pi
MQTT connection error
MQTT connection error
Verify the MQTT environment variable is set:Test MQTT connection from within container:
Out of disk space during build
Out of disk space during build
Docker builds require significant disk space. Clean up unused images:
Performance Optimization
Use Pre-built Images
Instead of building locally, pull pre-built images if available:
Multi-stage Builds
For production, consider creating a multi-stage Dockerfile to reduce final image size by separating build and runtime dependencies.
Cache Build Layers
When rebuilding, Docker caches intermediate layers. To rebuild from scratch:
Next Steps
Raspberry Pi Setup
Optimize YOLO-Pi for Raspberry Pi hardware
Model Conversion
Convert YOLO models to Keras format

