Overview
Docker deployment provides a consistent, isolated environment for running Iris without manually installing Rust, OpenCV, or system dependencies. This guide explains the Dockerfile architecture and deployment strategies.Docker is the recommended deployment method for production environments, ensuring reproducible builds across different systems.
Prerequisites
Dockerfile Architecture
Iris uses a single-stage Dockerfile based on the official Rust image with OpenCV dependencies:Dockerfile
Build Stages Explained
Base Image Selection
Base Image Selection
- Rust toolchain (rustc, cargo)
- Standard Linux utilities
- Debian package manager (apt)
System Dependencies
System Dependencies
- clang/llvm-dev/libclang-dev: Required for opencv-rust bindings compilation
- pkg-config: Locates library paths during build
- libopencv-dev: OpenCV 4.x headers and libraries
- curl: Downloads ONNX models
rm -rf /var/lib/apt/lists/*) reduces image size by ~40MB.Build Context
Build Context
/app as the working directory and copies source files.Copying
Cargo.toml/Cargo.lock before src/ enables Docker layer caching. Dependencies are only rebuilt if these files change.Compilation
Compilation
- Optimizations enabled (-O3 equivalent)
- Binary output:
/app/target/release/iris - Build time: ~8-12 minutes on first build
Model Download
Model Download
face_detection_yunet_2023mar.onnx(~360KB)face_recognition_sface_2021dec.onnx(~41MB)
/app/*.onnx.Runtime Configuration
Runtime Configuration
- EXPOSE 8080: Documents the API port (doesn’t publish it)
- CMD: Runs the compiled binary on container start
/app (WORKDIR), which matches the build paths.Building the Image
Build the Docker image
First build takes 10-15 minutes:
- Downloading Rust dependencies (~2-3 min)
- Compiling opencv-rust bindings (~5-7 min)
- Building application (~1-2 min)
- Downloading ONNX models (~30 sec)
Running the Container
Basic Usage
Run Iris in detached mode with port mapping:Command breakdown
Command breakdown
- -d: Detached mode (runs in background)
- —name iris: Container name for easy reference
- -p 8080:8080: Maps host port 8080 to container port 8080
- iris-api:latest: Image name and tag
Verify the Container
Check container status:Test the API
Verify the health endpoint:Advanced Configuration
Custom Port Mapping
Run on a different host port:http://localhost:3000
The container still listens on 8080 internally. Only the host mapping changes.
Resource Limits
Constrain CPU and memory usage:Recommended resource allocations
Recommended resource allocations
- Development: 1 CPU, 2GB RAM
- Production (low traffic): 2 CPUs, 4GB RAM
- Production (high traffic): 4+ CPUs, 8GB+ RAM
Environment Variables
While Iris doesn’t currently use environment variables, you can pass them for future extensibility:Volume Mounting
Mount external model files (useful for model updates without rebuilding):Persistent Logs
Redirect container logs to a file:Docker Compose
For multi-container setups or simplified orchestration:docker-compose.yml
Adding a reverse proxy (nginx)
Adding a reverse proxy (nginx)
docker-compose.yml
- Exposes Iris only to the internal Docker network
- Routes external traffic through nginx
- Enables HTTPS termination
Image Size Optimization
The default image is ~2.1GB. Reduce size using multi-stage builds:Dockerfile.optimized
Optimized image size: ~400MB (80% reduction)
Only runtime OpenCV libraries are included, eliminating build tools and Rust toolchain.
Production Deployment
Health Checks
Add Docker health checks for automatic restart on failure:docker-compose.yml
Security Hardening
Monitoring and Logging
Integrate with logging systems:Troubleshooting
Build fails: OpenCV not found
Build fails: OpenCV not found
Symptoms:Cause:
libopencv-dev installation failed in Dockerfile.Solution:- Update package lists: Add
apt-get updatebefore install - Use specific OpenCV version:
- Check Debian/Ubuntu compatibility with
rust:latestbase image
Model download fails during build
Model download fails during build
Symptoms:Cause: Network connectivity issues during
docker build.Solution:- Check Docker network settings
- Use
--network=hostflag: - Pre-download models and COPY instead:
Container exits immediately
Container exits immediately
Symptoms:Solution:
Check logs for errors:Common causes:
- Missing ONNX models in image
- Port 8080 permission issues (use
--cap-add=NET_BIND_SERVICE) - Panic during initialization (check model paths)
High memory usage
High memory usage
Symptoms: Container uses >4GB RAM.Cause: Multiple concurrent face recognition requests.Solution:
- Set memory limits:
- Reduce rate limit quota in
src/main.rs - Scale horizontally with multiple containers + load balancer
Cannot access API from host
Cannot access API from host
Symptoms:
curl: (7) Failed to connect to localhost port 8080Solution:- Verify port mapping:
docker ps(should show0.0.0.0:8080->8080/tcp) - Check firewall rules:
- Test from inside container:
Scaling with Docker
Horizontal Scaling
Run multiple Iris instances behind a load balancer:nginx.conf
Docker Swarm / Kubernetes
For orchestration at scale, see:- Docker Swarm deployment guide (coming soon)
- Kubernetes Helm chart (coming soon)
Registry and Distribution
Push to Docker Hub
Pull and Run
Others can now deploy Iris without building:Next Steps
API Reference
Integrate face comparison into your application
Local Installation
Alternative non-Docker setup guide
Security Model
Learn about privacy and security features
Architecture
Understand how Iris works under the hood