vLLM_VLM_OCR_Nginx / Dockerfile
GitLab CI
Deploy commit 7ea20479 via GitLab CI
20aa4c6
Raw History Blame Contribute Delete
5.08 kB
# =============================================================================
# vLLM dual-model (GLM-OCR + Qwen3-VL) + PP-DocLayoutV3 (CPU) + Nginx
# Hugging Face Space - Nvidia T4-small (16 Go VRAM, sm_75)
# Base: official vLLM nightly image, pinned by linux/amd64 digest (2026-11-02).
# Verified contents of this digest: vllm 0.33.0rc1.dev484, transformers 5.22.1
# (includes GlmOcrForConditionalGeneration), huggingface-hub 2.4.0, tokenizers 0.23.3.
# GLM-OCR needs transformers >= 5.x (arch `glm_ocr`) — stable vLLM images pin
# transformers<5 and crash with "model type glm_ocr ... not recognized"; the nightly
# ships the whole compatible stack, so NO pip override is needed.
# Qwen3-VL only needs vLLM >= 0.11.0 -> covered. sm_75 (T4) wheels included.
# Orchestration: supervisord (vllm-ocr, layout, vllm-vlm, warmup, nginx)
# =============================================================================
# /!
# Digest of the linux/amd64 sub-manifest ONLY. The manifest-list digest
# (sha256:d0a6498c...) is the arm64 build -> "exec format error" on amd64 builders.
FROM vllm/vllm-openai@sha256:7a933b7cf81799936262bd459ba9a13b589291f9edd6b0179dd7632969906a81
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1
# SECURITY: non-root user (UID/GID 1000 for HF Spaces compatibility).
# The vLLM nightly base image already ships a user/group with UID/GID 1000
# -> create only if missing, and run as numeric UID 1000 (name may differ).
RUN getent group 1000 >/dev/null 2>&1 || groupadd -g 1000 space
RUN getent passwd 1000 >/dev/null 2>&1 || useradd -u 1000 -g 1000 -m -d /home/space space
# System packages: Nginx (reverse proxy). supervisord is NOT taken from apt:
# the Ubuntu package (4.2.1) imports asynchat, removed from the stdlib in Python 3.12
# (the base vllm image ships Python 3.12) -> it crashes. We install supervisor via pip below.
RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
curl \
openssl \
ca-certificates \
pciutils \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Python deps for auth + orchestrator + layout service (torch/vllm/huggingface_hub already
# in base image). supervisor>=4.2.5 supports Python 3.12 (no asynchat).
# PP-DocLayoutV3 runs via ONNX Runtime on CPU: PaddlePaddle is intentionally NOT installed
# (it would conflict with torch/vLLM).
RUN pip3 install --no-cache-dir \
supervisor \
bcrypt==4.1.2 \
onnxruntime \
pillow \
numpy \
fastapi \
uvicorn \
httpx \
pymupdf \
|| pip3 install --no-cache-dir --break-system-packages \
supervisor \
bcrypt==4.1.2 \
onnxruntime \
pillow \
numpy \
fastapi \
uvicorn \
httpx \
pymupdf
# Application layout
RUN mkdir -p /home/space/.cache \
/tmp/hf \
/data/hf \
/scripts \
/var/log/nginx \
/var/lib/nginx \
/tmp/nginx/body \
/tmp/nginx/proxy \
/tmp/nginx/fastcgi \
/tmp/nginx/uwsgi \
/tmp/nginx/scgi \
/tmp/torch_extensions \
/tmp/.cache
# Nginx config, orchestration scripts and supervisord config
COPY nginx/ /etc/nginx/
COPY scripts/ /scripts/
COPY supervisord.conf /etc/supervisord.conf
RUN chmod +x /scripts/entrypoint.sh /scripts/warmup.sh /scripts/serve_vlm.sh /scripts/serve_nginx.sh /scripts/preload_models.sh /scripts/gpu_detect.py /scripts/generate_htpasswd.py /scripts/layout_service.py && \
chown -R 1000:1000 /home/space /data /scripts /etc/nginx /var/log/nginx /var/lib/nginx /tmp/nginx /tmp/.cache /tmp/hf && \
chmod 777 /tmp/hf && \
chmod -R 755 /etc/nginx /var/log/nginx /var/lib/nginx /tmp/nginx && \
chmod 777 /data && \
chmod 1777 /tmp
# Default environment (all overridable via HF Space secrets / docker-compose)
ENV HOME=/home/space \
HF_HOME=/tmp/hf \
XDG_CACHE_HOME=/tmp/.cache \
TORCH_EXTENSIONS_DIR=/tmp/torch_extensions \
OMP_NUM_THREADS=1 \
NGINX_PORT=7860 \
MODEL_OCR=zai-org/GLM-OCR \
MODEL_VLM=Qwen/Qwen3-VL-4B-Instruct \
SERVED_OCR=glm-ocr \
SERVED_VLM=qwen3-vl \
PORT_OCR=8001 \
PORT_VLM=8002 \
LAYOUT_PORT=8003 \
LAYOUT_MODEL=PaddlePaddle/PP-DocLayoutV3_onnx \
GPU_MEM_UTIL_OCR=0.25 \
GPU_MEM_UTIL_VLM=0.70 \
MAX_MODEL_LEN=4096 \
MAX_NUM_SEQS=2 \
MAX_IMAGE_PX=2250000 \
MIN_VRAM_MB=15000 \
MIN_CUDA_MAJOR=11 \
MIN_CUDA_MINOR=8
# Hugging Face Space port
EXPOSE 7860
# Long start period: nginx now binds port 7860 only after the models are loaded
# in VRAM (scripts/serve_nginx.sh), so this check can legitimately fail for a
# long time at boot.
HEALTHCHECK --interval=30s --timeout=10s --start-period=3600s --retries=3 \
CMD curl -f -u "${NGINX_USERNAME:-admin}:${NGINX_PASSWORD}" http://localhost:7860/health || exit 1
# SECURITY: run as non-root (numeric UID: base image may name the user differently)
USER 1000
ENTRYPOINT ["/scripts/entrypoint.sh"]