Add multi-target Dockerfiles for remote and local builds

Both root and backend Dockerfiles now use a shared base stage with
two targets: remote (lightweight, ~300MB) and local (full Docling,
~2-3GB). docker-compose uses CONVERSION_MODE to select the target.
This commit is contained in:
Pier-Jean Malandrino 2026-04-02 21:40:45 +02:00
parent 8dd917b6ed
commit 9ac0840607
3 changed files with 59 additions and 13 deletions

View file

@ -1,10 +1,10 @@
# syntax=docker/dockerfile:1
# =============================================================================
# Docling Studio — single-image build (frontend + backend)
# Docling Studio — single-image build (frontend + backend, multi-target)
#
# Usage:
# docker build -t docling-studio .
# docker run -p 3000:3000 docling-studio
# docker build --target remote -t docling-studio:remote .
# docker build --target local -t docling-studio:local .
# =============================================================================
# --- Stage 1: Build frontend assets ---
@ -18,21 +18,19 @@ RUN npm ci
COPY frontend/ .
RUN VITE_APP_VERSION=${APP_VERSION} npm run build
# --- Stage 2: Runtime (Python + Nginx) ---
FROM python:3.12-slim
# --- Stage 2: Base runtime (Python + Nginx) ---
FROM python:3.12-slim AS base
ARG APP_VERSION=dev
ENV APP_VERSION=${APP_VERSION}
# System deps: poppler (pdf2image), nginx, and OpenCV runtime libs
# System deps: poppler (pdf2image), nginx
RUN apt-get update && apt-get install -y --no-install-recommends \
poppler-utils \
libgl1 \
libglib2.0-0 \
nginx \
&& rm -rf /var/lib/apt/lists/*
# Python deps
# Python deps (common)
WORKDIR /app
COPY document-parser/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
@ -57,5 +55,22 @@ ENV DB_PATH=/app/data/docling_studio.db
EXPOSE 3000
# nginx needs to run as root for port binding, then drops to appuser for uvicorn
CMD ["sh", "-c", "nginx && exec su appuser -c 'uvicorn main:app --host 127.0.0.1 --port 8000'"]
# --- Remote: lightweight, delegates to Docling Serve ---
FROM base AS remote
ENV CONVERSION_ENGINE=remote
# --- Local: full Docling in-process ---
FROM base AS local
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
COPY document-parser/requirements-local.txt .
RUN pip install --no-cache-dir -r requirements-local.txt
RUN chown -R appuser:appuser /app
ENV CONVERSION_ENGINE=local

View file

@ -2,6 +2,7 @@ services:
document-parser:
build:
context: ./document-parser
target: ${CONVERSION_MODE:-local}
expose:
- "8000"
volumes:
@ -9,6 +10,8 @@ services:
- db_data:/app/data
environment:
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost:3000,http://localhost:5173}
DOCLING_SERVE_URL: ${DOCLING_SERVE_URL:-}
DOCLING_SERVE_API_KEY: ${DOCLING_SERVE_API_KEY:-}
deploy:
resources:
limits:

View file

@ -1,9 +1,17 @@
FROM python:3.12-slim
# syntax=docker/dockerfile:1
# =============================================================================
# Docling Studio — backend image (multi-target: remote / local)
#
# Usage:
# docker build --target remote -t docling-studio-backend:remote .
# docker build --target local -t docling-studio-backend:local .
# =============================================================================
# --- Base: common deps for both targets ---
FROM python:3.12-slim AS base
RUN apt-get update && apt-get install -y --no-install-recommends \
poppler-utils \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
@ -24,3 +32,23 @@ ENV DB_PATH=/app/data/docling_studio.db
USER appuser
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# --- Remote: lightweight, delegates to Docling Serve ---
FROM base AS remote
ENV CONVERSION_ENGINE=remote
# --- Local: full Docling in-process ---
FROM base AS local
USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements-local.txt .
RUN pip install --no-cache-dir -r requirements-local.txt
RUN chown -R appuser:appuser /app
USER appuser
ENV CONVERSION_ENGINE=local