feat(docling): persist model cache via Docker volume

- Add docling_models volume mounted at /models in container
- Set HF_HOME=/models/huggingface at runtime (via docker-compose env)
- Models download once → persist in volume → survive container rebuilds
- Build-time preload uses || to not block build if network unavailable

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-07 07:18:14 -08:00
parent 764613bd86
commit 73dee93d19
2 changed files with 10 additions and 2 deletions

View File

@ -256,8 +256,12 @@ services:
dockerfile: Dockerfile
container_name: iconsulting-docling
restart: unless-stopped
environment:
HF_HOME: /models/huggingface
ports:
- "3007:3007"
volumes:
- docling_models:/models
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:3007/health')"]
interval: 30s
@ -478,3 +482,5 @@ volumes:
driver: local
minio_data:
driver: local
docling_models:
driver: local

View File

@ -13,8 +13,10 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY app/ ./app/
COPY scripts/ ./scripts/
# 构建时预下载模型(实际执行一次 PDF 转换触发 HuggingFace 模型下载)
RUN python scripts/preload_models.py
# 模型缓存目录(运行时通过 Docker volume 持久化到 /models
# 构建时预下载到镜像默认路径;运行时 HF_HOME=/models/huggingface 由 volume 接管
ENV HF_HOME=/root/.cache/huggingface
RUN python scripts/preload_models.py || echo "Model preload skipped (will download on first request)"
EXPOSE 3007