From 73dee93d1966423adb06720083457087187a926a Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 7 Feb 2026 07:18:14 -0800 Subject: [PATCH] feat(docling): persist model cache via Docker volume MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- docker-compose.yml | 6 ++++++ packages/services/docling-service/Dockerfile | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2b057d2..92b194a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/packages/services/docling-service/Dockerfile b/packages/services/docling-service/Dockerfile index f556e69..1ec6503 100644 --- a/packages/services/docling-service/Dockerfile +++ b/packages/services/docling-service/Dockerfile @@ -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