Skip to content

Commit 1f78b76

Browse files
LocNgoXuan23claude
andauthored
feat(docker): add per-engine Docker dev environments (#649)
Replace the single legacy Dockerfile (rapidocr_api only) with 7 per-engine development images covering all supported inference backends: - onnxruntime-cpu: ONNX Runtime on CPU (python:3.10-slim-bookworm) - onnxruntime-gpu: ONNX Runtime with CUDA (nvidia/cuda:12.4.1) - tensorrt: NVIDIA TensorRT (nvcr.io/nvidia/deepstream:7.0-gc-triton-devel) - paddle: PaddlePaddle CPU - openvino: Intel OpenVINO - pytorch: PyTorch CPU - mnn: Alibaba MNN Infrastructure: - Dockerfile.base: shared foundation for CPU variants - docker-compose.yaml: all 7 services with shared model volume - Makefile: make build-*/test-*/shell-* convenience commands - .dockerignore: excludes .git, models, build artifacts Key design decisions: - PYTHONPATH-based imports (setup.py incompatible with pip editable install) - Named volume (rapidocr-models) for persistent model cache across rebuilds - Source bind-mounted at runtime for live editing - tensorrt pinned to 8.6.x + cuda-python 12.x (matching DeepStream 7.0) All 7 images built and tested with full OCR pipeline inference. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8ea9626 commit 1f78b76

16 files changed

Lines changed: 500 additions & 26 deletions

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# RapidOCR Docker Dev Environments
2+
COMPOSE_FILE := docker/docker-compose.yaml
3+
ENGINES := onnxruntime-cpu onnxruntime-gpu tensorrt paddle openvino pytorch mnn
4+
5+
.PHONY: help build-all clean $(foreach e,$(ENGINES),build-$(e) test-$(e) shell-$(e))
6+
7+
help:
8+
@echo "RapidOCR Docker Dev Environments"
9+
@echo ""
10+
@echo "Usage:"
11+
@echo " make build-{engine} Build a dev image"
12+
@echo " make test-{engine} Run tests in container"
13+
@echo " make shell-{engine} Open bash shell in container"
14+
@echo " make build-all Build all images"
15+
@echo " make clean Remove all containers and images"
16+
@echo ""
17+
@echo "Engines: $(ENGINES)"
18+
@echo ""
19+
@echo "Examples:"
20+
@echo " make build-tensorrt"
21+
@echo " make test-onnxruntime-cpu"
22+
@echo " make shell-pytorch"
23+
24+
build-%:
25+
docker compose -f $(COMPOSE_FILE) build $*
26+
27+
test-%:
28+
docker compose -f $(COMPOSE_FILE) run --rm $* pytest tests/ -v
29+
30+
shell-%:
31+
docker compose -f $(COMPOSE_FILE) run --rm $* bash
32+
33+
build-all:
34+
docker compose -f $(COMPOSE_FILE) build
35+
36+
clean:
37+
docker compose -f $(COMPOSE_FILE) down --rmi local --volumes

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ print(result)
7171
result.vis("vis_result.jpg")
7272
```
7373

74+
### 🐳 Docker
75+
76+
Docker development environments are available for all supported inference engines:
77+
78+
```bash
79+
# Build and test with ONNX Runtime (CPU)
80+
make build-onnxruntime-cpu
81+
make test-onnxruntime-cpu
82+
83+
# Or use any engine: onnxruntime-gpu, tensorrt, paddle, openvino, pytorch, mnn
84+
make build-tensorrt
85+
make shell-tensorrt
86+
```
87+
88+
See [docker/README.md](./docker/README.md) for full setup instructions, GPU configuration, and troubleshooting.
89+
7490
### 📚 Documentation
7591

7692
Full documentation can be found on [docs](https://rapidai.github.io/RapidOCRDocs/), in Chinese.

docker/.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.git
2+
__pycache__
3+
*.pyc
4+
*.pyo
5+
*.egg-info
6+
dist/
7+
build/
8+
.tox/
9+
.pytest_cache/
10+
.mypy_cache/
11+
python/rapidocr/models/
12+
python/benchmark_*
13+
python/pred.txt
14+
python/merged_benchmark_report_*
15+
python/tensorrt_build_logs_*
16+
python/validate_benchmark_*
17+
python/generate_merged_report.py
18+
python/mnn_benchmark_reference.md
19+
*.engine
20+
.mcp.json

docker/Dockerfile.base

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM python:3.10-slim-bookworm
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV PYTHONDONTWRITEBYTECODE=1
5+
ENV PYTHONUNBUFFERED=1
6+
ENV PYTHONPATH=/app
7+
8+
WORKDIR /app
9+
10+
# System dependencies for opencv, pyclipper, shapely C extensions
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
libgl1 \
13+
libglib2.0-0 \
14+
libsm6 \
15+
libxext6 \
16+
libxrender1 \
17+
gcc \
18+
g++ \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Copy only requirements first for layer caching
22+
COPY python/requirements.txt /tmp/requirements.txt
23+
24+
# Install core deps with opencv-headless (no GUI needed in container)
25+
RUN pip install --no-cache-dir --upgrade pip && \
26+
pip install --no-cache-dir -r /tmp/requirements.txt && \
27+
pip uninstall -y opencv-python 2>/dev/null; \
28+
pip install --no-cache-dir opencv-python-headless && \
29+
pip install --no-cache-dir pytest && \
30+
rm /tmp/requirements.txt
31+
32+
# Copy source (bind-mounted at runtime for live editing via docker-compose)
33+
COPY python/ /app/
34+
35+
CMD ["bash"]

docker/Dockerfile.mnn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM rapidocr-base:latest
2+
3+
RUN pip install --no-cache-dir MNN
4+
5+
CMD ["bash"]

docker/Dockerfile.onnxruntime-cpu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM rapidocr-base:latest
2+
3+
RUN pip install --no-cache-dir onnxruntime
4+
5+
CMD ["bash"]

docker/Dockerfile.onnxruntime-gpu

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV PYTHONDONTWRITEBYTECODE=1
5+
ENV PYTHONUNBUFFERED=1
6+
ENV PYTHONPATH=/app
7+
8+
WORKDIR /app
9+
10+
# Install Python 3.10 and system deps
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
software-properties-common \
13+
&& add-apt-repository ppa:deadsnakes/ppa \
14+
&& apt-get update \
15+
&& apt-get install -y --no-install-recommends \
16+
python3.10 \
17+
python3.10-venv \
18+
python3.10-dev \
19+
python3-pip \
20+
libgl1 \
21+
libglib2.0-0 \
22+
libsm6 \
23+
libxext6 \
24+
libxrender1 \
25+
gcc \
26+
g++ \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
# Make python3.10 the default
30+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 && \
31+
update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
32+
33+
# Copy and install deps
34+
COPY python/requirements.txt /tmp/requirements.txt
35+
36+
RUN python -m pip install --no-cache-dir --upgrade pip && \
37+
pip install --no-cache-dir -r /tmp/requirements.txt && \
38+
pip uninstall -y opencv-python 2>/dev/null; \
39+
pip install --no-cache-dir opencv-python-headless && \
40+
pip install --no-cache-dir pytest && \
41+
rm /tmp/requirements.txt
42+
43+
# Install ONNX Runtime GPU
44+
RUN pip install --no-cache-dir onnxruntime-gpu
45+
46+
# Copy source (bind-mounted at runtime for live editing via docker-compose)
47+
COPY python/ /app/
48+
49+
CMD ["bash"]

docker/Dockerfile.openvino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM rapidocr-base:latest
2+
3+
RUN pip install --no-cache-dir openvino==2023.3.0
4+
5+
CMD ["bash"]

docker/Dockerfile.paddle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM rapidocr-base:latest
2+
3+
# PaddlePaddle CPU uses a special index URL
4+
RUN pip install --no-cache-dir paddlepaddle==3.1.1 \
5+
-i https://www.paddlepaddle.org.cn/packages/stable/cpu/
6+
7+
CMD ["bash"]

docker/Dockerfile.pytorch

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM rapidocr-base:latest
2+
3+
# PyTorch CPU from official index
4+
RUN pip install --no-cache-dir torch torchvision torchaudio \
5+
--index-url https://download.pytorch.org/whl/cpu
6+
7+
CMD ["bash"]

0 commit comments

Comments
 (0)