Skip to content

Fix docker build setup#5

Open
MacJedi42 wants to merge 9 commits into
Bogdanovich77:mainfrom
MacJedi42:fix-docker-build-setup
Open

Fix docker build setup#5
MacJedi42 wants to merge 9 commits into
Bogdanovich77:mainfrom
MacJedi42:fix-docker-build-setup

Conversation

@MacJedi42

@MacJedi42 MacJedi42 commented Oct 23, 2025

Copy link
Copy Markdown

Fix Docker Build Setup and Volume Mount Issue

Problem Fixed

The current Docker setup fails with HFValidationError when running docker compose build && docker compose up because of a volume mount conflict:

HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name':
'/app/models/deepseek-ai/DeepSeek-OCR'

Root Cause

  1. Dockerfile runs setup_deepseek.sh which downloads the model inside the container during build
  2. docker-compose.yml has ./models:/app/models volume mount
  3. When container starts, the mount overwrites the container's /app/models/ with the (empty) host's ./models/ directory
  4. Container can't find model files and crashes with HFValidationError

Solution

This PR fixes the issue by enforcing proper setup order:

  1. Download model to HOST first using setup_local.sh
  2. Then build Docker - setup_deepseek.sh now only clones source code
  3. Then start container - model is mounted from host via volume

Key Changes

New Files Added

  1. setup_local.sh - Pre-build setup script

    • Downloads DeepSeek-OCR model (~15GB) to ./models/
    • Clones DeepSeek-OCR source code
    • Validates setup completion
    • Must be run BEFORE docker compose build
  2. build_and_run.sh (Linux/macOS) - All-in-one automated script

    • Checks prerequisites (Docker, GPU, nvidia-smi)
    • Runs setup_local.sh if needed
    • Builds Docker image
    • Optionally starts the service
    • Provides clear error messages
  3. CLAUDE.md - Comprehensive codebase documentation

    • Architecture overview and key implementation details
    • Volume mount strategy explanation
    • Development commands and workflows
    • Troubleshooting guide for common issues
    • Critical setup order requirements
    • Useful for anyone using Claude-Code to understand the repo

Modified Files

  1. setup_deepseek.sh

    • Removed model download logic (would be overridden by volume mount)
    • Now only clones DeepSeek-OCR source code from GitHub
    • Added note about volume mount requirement
  2. build.bat (Windows)

    • Added prerequisite checks (Docker, Docker Compose, GPU)
    • Added setup status verification
    • Enforces setup order before building
    • Prevents build if model/source missing
    • Interactive service startup option
    • Updated to use docker compose (v2) instead of deprecated docker-compose
    • Integrated upstream's OCR functionality notes
  3. All script references updated

    • Changed from deprecated docker-compose to docker compose (Docker CLI plugin v2)
    • Updated all documentation and scripts accordingly

Breaking Changes

REQUIRED: Run Setup Before Building

Users must now run setup_local.sh (or build_and_run.sh) before building Docker:

# OLD (broken) workflow:
docker compose build
docker compose up -d

# NEW (correct) workflow:
./setup_local.sh          # Download model first
docker compose build      # Then build
docker compose up -d      # Then start

# OR use automated script:
./build_and_run.sh        # Handles everything

Why This Approach?

Pros:

  • Model (~6GB) stays on host, not duplicated in Docker image layers
  • Easy to update model without rebuilding container
  • Clear separation between setup (one-time) and runtime
  • Volume mount allows model sharing between container runs
  • Faster subsequent builds (no model download)

Cons:

  • Requires extra step before Docker build (mitigated by automated scripts)
  • Model must exist on host machine

Testing Performed

Tested the complete workflow from clean state:

# Clean slate
docker compose down
rm -rf models/ DeepSeek-OCR/

# Run automated setup
./build_and_run.sh

# Verify service started
curl http://localhost:8000/health
# Returns: {"status": "healthy", "model_loaded": true, ...}

# Test API endpoint
curl -X POST "http://localhost:8000/ocr/pdf" -F "file=@test.pdf"
# Successfully processes PDF

Compatibility

  • Compatible with all upstream changes (custom prompts, enhanced processors)
  • Preserves all existing functionality
  • Works on Linux, macOS, and Windows
  • No changes to API endpoints or response formats
  • Existing docker-compose.yml unchanged
  • Python scripts continue to work as before

Documentation Updates

  • Added comprehensive setup instructions in CLAUDE.md for AI assisted dev workflows from other contributors
  • Added troubleshooting section for HFValidationError
  • Updated all command examples to use docker compose (v2)
  • Clarified volume mount behavior
  • Added critical setup order documentation

Merge Notes

This PR includes a merge of upstream changes from main branch:

  • Custom prompt support with YAML configuration
  • Enhanced PDF processors with image extraction
  • OCR-specific processing scripts
  • Updated GPU memory requirements (12GB minimum)
  • Additional custom configuration files

All conflicts have been resolved while preserving both the fixes from this branch and the new features from upstream.

Checklist

  • Tested on clean environment
  • Verified model loading works
  • API endpoints functional
  • Batch processor works
  • Documentation updated
  • Scripts use docker compose (not docker-compose)
  • Conflicts resolved
  • No breaking changes to API

Related Issues

Fixes the Docker build failure reported by users trying to follow README setup instructions.


Note: This is a critical fix for users unable to run the Docker container. Without this fix, following the README instructions results in immediate container failure.

MacJedi42 and others added 7 commits October 22, 2025 15:22
Fixed AI mistakes in Docker deployment instructions: 

docker-compose is legacy and no longer used, docker compose is correct.
  This commit resolves Docker build failures caused by missing DeepSeek-OCR
  source code and model files. The build now automatically downloads all
  required dependencies.

  Changes:
  - Add DeepSeek-OCR/requirements.txt with all Python dependencies
    * Core: PyMuPDF, img2pdf, einops, easydict, addict, Pillow, numpy
    * API: fastapi==0.104.1, uvicorn[standard]==0.24.0
    * Model: flash-attn==2.7.3, tokenizers==0.13.3
    * Utils: tqdm, requests

  - Update Dockerfile for automatic dependency management
    * Install git and huggingface-cli for downloads
    * Add automated source code download from GitHub
    * Add automated model download from Hugging Face (~6GB)
    * Remove hard-coded dependency installation (now uses requirements.txt)

  - Add setup_deepseek.sh for Docker build automation
    * Downloads DeepSeek-OCR source from GitHub if missing
    * Downloads model from Hugging Face if missing
    * Verifies all required files (config.json, tokenizer_config.json)
    * Updates config.py with correct model paths
    * Provides colored status output

  - Add setup_local.sh for local pre-download workflow
    * Pre-downloads source and model before Docker build
    * Enables faster Docker rebuilds (model cached locally)
    * Supports resume for interrupted downloads
    * Validates setup completion

  - Add QUICKSTART.md comprehensive setup documentation
    * Two setup workflows: automatic vs pre-download
    * Troubleshooting guide for common issues
    * API endpoint documentation
    * Performance tuning recommendations

  The Docker build now works with either:
  1. Automatic: docker-compose build (downloads during build)
  2. Pre-download: ./setup_local.sh && docker-compose build (faster rebuilds)

	modified:   Dockerfile
	new file:   QUICKSTART.md
	modified:   README.md
	new file:   setup_deepseek.sh
	new file:   setup_local.sh
     ## Problem Fixed

     The original setup had a critical issue where running `docker compose build` and `docker compose up` would fail with:

     ```
     HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name':
     '/app/models/deepseek-ai/DeepSeek-OCR'
     ```

     ## Root Cause

     The issue was caused by a volume mount conflict:

     1. `Dockerfile` ran `setup_deepseek.sh` which downloaded the model **inside the container** during build
     2. `docker-compose.yml` had `./models:/app/models` volume mount
     3. When container started, the mount **replaced** the container's `/app/models/` with the (empty) host's `./models/` directory
     4. Container couldn't find model files and crashed

     ## Solution

     The fix enforces proper setup order:

     1. **Download model to HOST first** using `setup_local.sh`
     2. **Then build Docker** - `setup_deepseek.sh` no longer downloads model, only clones source code
     3. **Then start container** - model is mounted from host via volume

     ## Changes Made

     ### 1. Updated `setup_deepseek.sh`
     - Removed model download logic (since it would be overridden by volume mount anyway)
     - Now only clones DeepSeek-OCR source code
     - Added note about volume mount requirement

     ### 2. Created `build_and_run.sh` (Linux/macOS)
     - All-in-one script that enforces correct order
     - Checks prerequisites (Docker, GPU, etc.)
     - Runs `setup_local.sh` if model/source missing
     - Builds Docker image
     - Optionally starts service
     - Usage: `./build_and_run.sh`

     ### 3. Updated `build.bat` (Windows)
     - Same functionality as `build_and_run.sh` for Windows users
     - Checks prerequisites and setup status
     - Provides clear error messages if setup needed
     - Usage: `build.bat`

     ### 4. Updated All Scripts to Use `docker compose`
     - Changed from deprecated `docker-compose` to `docker compose` (v2 CLI plugin)
     - Updated all documentation and scripts

     ### 5. Updated `CLAUDE.md`
     - Added critical "Volume Mount Strategy" section
     - Added "HFValidationError" troubleshooting section
     - Updated all commands to use `docker compose`
     - Clarified setup order requirements

     ## How to Use Now

     ### Quick Start (Recommended)

     ```bash
     # Linux/macOS
     ./build_and_run.sh

     # Windows
     build.bat
     ```

     These scripts will:
     1. Check if model/source are downloaded
     2. Run setup if needed
     3. Build Docker image
     4. Start service (optional)

     ### Manual Setup (If Needed)

     ```bash
     # Step 1: Download model and clone source (ONE TIME ONLY)
     ./setup_local.sh

     # Step 2: Build Docker image
     docker compose build

     # Step 3: Start service
     docker compose up -d

     # Step 4: Check health
     curl http://localhost:8000/health
     ```

     ## Why This Approach?

     **Pros:**
     - Model (~15GB) stays on host, not duplicated in Docker image
     - Easy to update model without rebuilding container
     - Clear separation of concerns: setup vs runtime
     - Volume mount allows model sharing between runs

     **Cons:**
     - Requires extra step before Docker build
     - Model must exist on host machine

     ## What Happens If You Skip Setup?

     If you run `docker compose up` without running `setup_local.sh` first:

     1. Container starts with empty `/app/models/` directory (from empty host mount)
     2. `start_server.py` tries to load model from `/app/models/deepseek-ai/DeepSeek-OCR`
     3. Transformers library sees the path and tries to interpret it as a HuggingFace repo ID
     4. Validation fails: path format doesn't match `namespace/repo_name` pattern
     5. Container exits with `HFValidationError`
     6. Docker restart policy keeps retrying, same error repeats

     ## Testing

     To verify the fix works:

     ```bash
     # Clean slate
     docker compose down
     rm -rf models/ DeepSeek-OCR/

     # Run automated setup and build
     ./build_and_run.sh  # Should complete successfully

     # Check logs
     docker compose logs deepseek-ocr  # Should show "Model initialization complete!"

     # Test API
     curl http://localhost:8000/health  # Should return "healthy" status
     ```

     ## Files Modified

     - `setup_deepseek.sh` - Removed model download, only clones source
     - `build_and_run.sh` - NEW: Automated Linux/macOS setup and build script
     - `build.bat` - Updated for proper setup enforcement and `docker compose`
     - `CLAUDE.md` - Added volume mount explanation and troubleshooting
     - `SETUP_FIX_NOTES.md` - NEW: This file

     ## Files Unchanged

     - `setup_local.sh` - Already worked correctly, no changes needed
     - `Dockerfile` - No changes needed
     - `docker-compose.yml` - No changes needed
     - `start_server.py` - No changes needed
     - `pdf_to_markdown_processor.py` - No changes needed

  I've enforced the correct setup order:

  1. Download model to your local machine FIRST → ./models/
  2. Then build Docker → Container expects model to be mounted
  3. Then start container → Volume mount provides the model files

  Changes Made

  1. New build_and_run.sh (Linux/macOS all-in-one script)

  ./build_and_run.sh
  - Checks prerequisites
  - Runs setup_local.sh if needed
  - Builds Docker image
  - Optionally starts service

  2. Updated build.bat (Windows version)

  - Same functionality as above
  - Now enforces setup order
  - Uses docker compose instead of deprecated docker-compose

  3. Updated setup_deepseek.sh

  - No longer downloads model during Docker build
  - Only clones DeepSeek-OCR source code
  - Model must exist on host

  4. Updated all commands to use docker compose (not docker-compose)

  - docker compose build
  - docker compose up -d
  - docker compose logs -f
  - etc.

  5. Updated CLAUDE.md

  - Added "Volume Mount Strategy" section explaining why this is necessary
  - Added specific troubleshooting for the HFValidationError
  - Clarified critical setup order

  How to Use Now

  Quick Start (Recommended):

  ./build_and_run.sh  # Linux/macOS
  # OR
  build.bat          # Windows

  Manual Steps:

  # Step 1: Download model (~15GB, ONE TIME only)
  ./setup_local.sh

  # Step 2: Build Docker
  docker compose build

  # Step 3: Start service
  docker compose up -d

  # Step 4: Verify
  curl http://localhost:8000/health
	new file:   CLAUDE.md
	new file:   SETUP_FIX_NOTES.md
	modified:   build.bat
	new file:   build_and_run.sh
	modified:   setup_deepseek.sh
This merge brings in upstream enhancements while preserving the critical
Docker build setup fixes. Key changes:

Fixes from this branch:
- Fix Docker volume mount issue causing HFValidationError on startup
- Add setup_local.sh to download model before Docker build
- Add build_and_run.sh automated setup and build script
- Update all scripts to use 'docker compose' instead of deprecated 'docker-compose'
- Add CLAUDE.md for better codebase documentation
- Add SETUP_FIX_NOTES.md explaining the fix

Upstream features merged:
- Custom prompt support with YAML configuration
- Enhanced PDF processors with image extraction
- OCR-specific processing scripts
- Additional custom configuration files
- Updated GPU memory requirements (12GB minimum)

Conflict resolution:
- build.bat: Combined interactive service startup with OCR functionality notes
- All docker-compose commands updated to docker compose format

Co-authored-by: Bogdanovich77 <bogdanovich77@users.noreply.github.com>
- Add prominent automated setup section at the top of Quick Start
- Update Docker Backend Setup with clear warnings about setup order
- Replace all 'docker-compose' with 'docker compose' (v2)
- Add HFValidationError troubleshooting as first common issue
- Include detailed solution steps for the volume mount issue
- Emphasize that model must be downloaded locally first
- Reference build_and_run.sh and build.bat automated scripts
The README.md now includes:
- Automated setup instructions at the top
- Clear quick start guide with recommended approach
- Detailed manual setup instructions
- Troubleshooting section

QUICKSTART.md is no longer needed and would create redundant documentation.
Comment thread CLAUDE.md
Comment thread SETUP_FIX_NOTES.md Outdated
Corrected docker compose in follow up 'Next Steps' instructions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants