Pre-configured Docker images for developing and testing RapidOCR with each supported inference engine.
- Docker (20.10+)
- Docker Compose (v2)
- NVIDIA Container Toolkit (GPU images only)
| Image | Engine | Base Image | GPU Required |
|---|---|---|---|
onnxruntime-cpu |
ONNX Runtime (CPU) | python:3.10-slim-bookworm |
No |
onnxruntime-gpu |
ONNX Runtime (CUDA) | nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04 |
Yes |
tensorrt |
NVIDIA TensorRT | nvcr.io/nvidia/deepstream:7.0-gc-triton-devel |
Yes |
paddle |
PaddlePaddle (CPU) | python:3.10-slim-bookworm |
No |
openvino |
Intel OpenVINO | python:3.10-slim-bookworm |
No |
pytorch |
PyTorch (CPU) | python:3.10-slim-bookworm |
No |
mnn |
MNN | python:3.10-slim-bookworm |
No |
All commands run from the repository root.
make build-onnxruntime-cpumake test-onnxruntime-cpumake shell-onnxruntime-cpumake build-allmake clean# Build
docker compose -f docker/docker-compose.yaml build onnxruntime-cpu
# Run tests
docker compose -f docker/docker-compose.yaml run --rm onnxruntime-cpu pytest tests/ -v
# Run a single test
docker compose -f docker/docker-compose.yaml run --rm onnxruntime-cpu pytest tests/test_engine.py -k "onnxruntime" -v
# Interactive shell
docker compose -f docker/docker-compose.yaml run --rm onnxruntime-cpu bashGPU images (onnxruntime-gpu, tensorrt) require the NVIDIA Container Toolkit and a compatible NVIDIA GPU.
Verify your GPU is accessible:
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smiThen build and use GPU images normally:
make build-tensorrt
make test-tensorrt
make shell-tensorrtNote: TensorRT builds optimized engine files from ONNX models on first run. This takes several minutes per model. Subsequent runs use cached engines from the persistent model volume.
Your local python/ directory is bind-mounted into the container at /app. Any code changes you make on the host are immediately reflected inside the container — no rebuild needed.
A shared Docker volume (rapidocr-models) is mounted at /app/rapidocr/models/. Models are automatically downloaded on first use and cached in this volume. The cache persists across container rebuilds, so models are only downloaded once.
To clear the model cache:
docker volume rm rapidocr-modelsdocker/
├── Dockerfile.base # Shared base: Python 3.10, system deps, core pip packages
├── Dockerfile.onnxruntime-cpu # extends base + onnxruntime
├── Dockerfile.onnxruntime-gpu # standalone CUDA image + onnxruntime-gpu
├── Dockerfile.tensorrt # standalone DeepStream image + tensorrt + cuda-python
├── Dockerfile.paddle # extends base + paddlepaddle
├── Dockerfile.openvino # extends base + openvino
├── Dockerfile.pytorch # extends base + torch
├── Dockerfile.mnn # extends base + MNN
├── docker-compose.yaml # Service definitions, volumes, GPU reservations
└── .dockerignore # Excludes .git, models, build artifacts
Makefile # Convenience targets (repo root)
CPU images extend Dockerfile.base. GPU images (onnxruntime-gpu, tensorrt) use NVIDIA base images and replicate the base setup because they need CUDA pre-installed.
make shell-onnxruntime-cpu
# Inside container:
python -c "
from rapidocr import RapidOCR
engine = RapidOCR()
result = engine('tests/test_files/ch_en_num.jpg')
print(result)
"make shell-pytorch
# Inside container:
python -c "
from rapidocr import RapidOCR, EngineType
engine = RapidOCR(params={
'Det.engine_type': EngineType.TORCH,
'Cls.engine_type': EngineType.TORCH,
'Rec.engine_type': EngineType.TORCH,
})
result = engine('tests/test_files/ch_en_num.jpg')
print(result)
"docker compose -f docker/docker-compose.yaml run --rm onnxruntime-cpu \
pytest tests/test_engine.py::test_ppocrv5_rec_mobile -vEnsure you have Docker Compose v2 installed. On older systems, the command may be docker-compose (with hyphen) instead of docker compose (with space).
- Verify the NVIDIA driver:
nvidia-smi - Verify the container toolkit:
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi - If using Docker Desktop, enable GPU support in Settings > Resources > GPU.
This means the TensorRT or CUDA Python version doesn't match your host driver. The Dockerfile pins tensorrt>=8.6,<8.7 and cuda-python>=12.0,<13.0 for DeepStream 7.0. If your driver is older, you may need to adjust these versions.
Ensure the rapidocr-models volume is mounted. Check with docker volume ls | grep rapidocr.