# ProofMode Docker Examples
This directory contains examples of how to use ProofMode with Docker.
## Quick Start
```bash
# Run the interactive example script
./run-example.sh
# Or run all examples at once
./run-example.sh all
```
## Prerequisites
- Docker installed and running
- Docker Compose (optional, for compose examples)
## Examples
### 1. Basic Docker Run
Generate a proof for a single image:
```bash
docker run --rm \
--user $(id -u):$(id -g) \
-v ./input:/app/input:ro \
-v ./output:/app/output \
proofmode-rust:local \
generate -f /app/input/image.jpg -s /app/output
```
### 2. Docker Compose
Use the provided `docker-compose.yml` to run ProofMode as a service:
```bash
# Generate proof for a single file
docker-compose up proofmode
# Run in watch mode (monitors directory for new files)
docker-compose up proofmode-watch
```
### 3. Batch Processing
Process multiple files:
```bash
docker run --rm \
--user $(id -u):$(id -g) \
-v ./input:/app/input:ro \
-v ./output:/app/output \
proofmode-rust:local \
generate -d /app/input -s /app/output
```
### 4. Custom Configuration
Mount a custom configuration file:
```bash
docker run --rm \
--user $(id -u):$(id -g) \
-v ./input:/app/input:ro \
-v ./output:/app/output \
-v ./config.toml:/config.toml:ro \
proofmode-rust:local \
generate -f /app/input/image.jpg -s /app/output
```
### 5. Interactive Mode
Run an interactive shell to explore ProofMode commands:
```bash
docker run --rm -it \
--user $(id -u):$(id -g) \
-v ./input:/app/input:ro \
-v ./output:/app/output \
--entrypoint /bin/sh \
proofmode-rust:local
```
## Directory Structure
```
docker/
├── README.md # This file
├── docker-compose.yml # Docker Compose configuration
├── run-example.sh # Interactive example script
├── input/ # Place your media files here
├── output/ # Generated proofs will be saved here
└── config.toml # Custom configuration (created by script)
```
## Environment Variables
- `RUST_LOG`: Set log level (trace, debug, info, warn, error)
- `PGP_PASSPHRASE`: PGP passphrase for signing proofs (used during key generation)
- `PROOFMODE_IMAGE`: Override the Docker image to use
## Available Commands
ProofMode currently supports three CLI commands:
- `generate`: Create cryptographic proof bundles for media files
- `check`: Verify media files and their proofs
- `sign`: Certificate signing (placeholder for future functionality)
## Docker Volumes
The examples use bind mounts for simplicity, but you can also use Docker volumes:
```bash
# Create a named volume
docker volume create proofmode-data
# Use the volume
docker run --rm \
--user $(id -u):$(id -g) \
-v ./input:/app/input:ro \
-v proofmode-data:/app/output \
proofmode-rust:local \
generate -f /app/input/image.jpg -s /app/output
```
## Building Your Own Image
If you want to build the Docker image locally:
```bash
# From the project root directory
docker build -t proofmode-rust:local .
# Use your local image
PROOFMODE_IMAGE=proofmode-rust:local ./run-example.sh
```
## Troubleshooting
1. **Permission Issues**: The Docker container runs as a non-root user. When using bind mounts, ensure the container user has write permissions by using `--user $(id -u):$(id -g)` flag.
2. **Docker Compose User Mapping**: Set the USER_ID and GROUP_ID environment variables:
```bash
USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose up
```
3. **Image Not Found**: Build the image locally:
```bash
docker build -t proofmode-rust:local .
```
4. **Out of Memory**: For large media files, increase Docker's memory limit.
## Integration Examples
### Python Script Integration
```python
import subprocess
import json
def generate_proof(input_file, output_dir):
user_id = os.getuid()
group_id = os.getgid()
cmd = [
"docker", "run", "--rm",
"--user", f"{user_id}:{group_id}",
"-v", f"{input_file}:/app/input/file:ro",
"-v", f"{output_dir}:/app/output",
"proofmode-rust:local",
"generate", "-f", "/app/input/file", "-s", "/app/output"
]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
# Parse the output to get the hash
# Read the generated proof file
pass
```
### CI/CD Pipeline Integration
```yaml
# .gitlab-ci.yml example
generate-proofs:
image: proofmode-rust:local
script:
- proofmode generate -d artifacts/ -s proofs/
artifacts:
paths:
- proofs/
```