Ashari Abidin's Developer Docs

OpenClaw OCR Docker Setup

OpenClaw OCR Automation MVP Red Edition · 2 Containers

High-performance OCR pipeline with FastAPI + Tesseract and an intelligent watcher agent. Built for document automation, AI extraction, and red‑hot efficiency.

OCR API (FastAPI) Watcher Agent (Watchdog) JSON OCR Results
Final Architecture · Crimson Flow
+------------------+ +------------------+ +------------------+ +------------------+ | Upload Folder | --> | Watcher Agent | --> | OCR API | --> | JSON OCR Result | | ./uploads | | (watchdog) | | FastAPI+Tesseract| | (text/json) | +------------------+ +------------------+ +------------------+ +------------------+
1. Uploads/
Image lands
2. Watcher Agent
Monitors & triggers
3. OCR API
Extracts text
4. JSON Result
Structured output
Docker Containers (Ruby Red Stack): ocr-api (FastAPI + Tesseract) and openclaw-agent (watchdog automation). Fully independent, scalable, built for production OCR pipelines.
1. Install Docker on Ubuntu
1 Install Docker & Compose
sudo apt update copy
sudo apt update && sudo apt install -y docker.io docker-compose-plugin
2 Enable & Start Docker
systemctl copy
sudo systemctl enable docker && sudo systemctl start docker
3 User Group (no sudo)
add user to docker group copy
sudo usermod -aG docker $USER && newgrp docker
4 Verify Installation
check versions copy
docker --version && docker compose version
Project Setup & OCR API Container
5-6 Create folder structure
from home copy all
mkdir -p ~/.openclaw/openclaw-ocr-mvp ~/.openclaw/openclaw-agent
cd ~/.openclaw/openclaw-ocr-mvp && mkdir uploads outputs
7-9 Requirements & FastAPI main.py (OCR engine)
📄 requirements.txt
fastapi uvicorn[standard] python-multipart pillow pytesseract numpy
🐍 main.py (OCR endpoint)
POST /ocr → accepts image, runs Tesseract, returns JSON with extracted text.
// full code: FastAPI app with OCR extraction
10-11 Dockerfile & docker-compose.yml
Dockerfile (OCR API) copy
FROM python:3.11
RUN apt-get update && apt-get install -y tesseract-ocr
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
docker-compose.yml copy
services:
ocr-api:
build: .
ports: ["8000:8000"]
volumes: ["./uploads:/app/uploads", "./outputs:/app/outputs"]
restart: unless-stopped
12-14 Build & Run OCR API
build & start copy
cd ~/.openclaw/openclaw-ocr-mvp
docker compose build --no-cache
docker compose up -d
curl http://localhost:8000 # expect {"status":"running"}
VERIFIED OCR API live on port 8000 — ready for automation integration.
Watcher Automation Agent (Container 2)
15-17 Prepare watcher script
requirements.txt (agent) copy
watchdog requests
watcher.py (core logic) copy structure
import time, requests, os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class OCRHandler(FileSystemEventHandler):
def on_created(self, event):
if not event.is_directory:
time.sleep(0.5)
with open(event.src_path, 'rb') as f:
res = requests.post('http://host.docker.internal:8000/ocr', files={'file': f})
print(res.json())

observer = Observer()
observer.schedule(OCRHandler(), '/data/inbox', recursive=False)
observer.start()
while True: time.sleep(1)
18-20 Build & Run Watcher Container
build agent image copy
cd ~/.openclaw/openclaw-agent
docker build -t openclaw-agent .
docker run -it --name openclaw-agent -v ~/.openclaw/openclaw-ocr-mvp/uploads:/data/inbox --add-host=host.docker.internal:host-gateway openclaw-agent
The watcher displays Watching folder... and automatically processes any image dropped into uploads/ — prints JSON results with extracted text.
Test Automation Workflow
21-23 Test with sample image
Simulate file upload copy command
cp ~/Downloads/sample.jpg ~/.openclaw/openclaw-ocr-mvp/uploads/
Expected Watcher Log (red output)
[NEW FILE] /data/inbox/sample.jpg
{'filename': 'sample.jpg', 'text': 'Extracted content from image...', 'status': 'success'}
docker ps
Shows ocr-api and openclaw-agent both active.
Restart commands
docker compose restart (OCR API)
docker restart openclaw-agent

Stop services: docker compose down (inside OCR folder) and docker stop openclaw-agent
Monitoring & Container Management
Active containers
docker ps copy
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
View OCR logs
logs copy
docker logs ocr-api -f
docker logs openclaw-agent -f
Both containers run independently in a red-themed automation suite — perfect for AI extraction, document intelligence, and serverless-style processing.
Final Deployment Architecture · Crimson Edition
Docker Containers (Red Stack) ├── ocr-api (FastAPI + Tesseract) → exposed on port 8000 └── openclaw-agent (watchdog + requests) → mounts ./uploads Workflow: Image Upload → ./uploads/ → watcher detects new file → POST /ocr → Tesseract OCR → JSON result printed

MVP Ready — Red Hot Automation. Modular, lightweight, production-grade foundation. Extend with LLM post‑processing, queue systems, or cloud storage.

OCR API quick health check copy
curl -X POST http://localhost:8000/ocr -F "file=@test.png" | jq .
OpenClaw OCR Automation MVP · Red Theme · Powered by Docker, FastAPI, Tesseract & Watchdog · Ready for agentic document workflows
Back