Fix docker build setup#5
Open
MacJedi42 wants to merge 9 commits into
Open
Conversation
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.
Isaac4real
reviewed
Oct 23, 2025
Isaac4real
reviewed
Oct 23, 2025
Corrected docker compose in follow up 'Next Steps' instructions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Docker Build Setup and Volume Mount Issue
Problem Fixed
The current Docker setup fails with
HFValidationErrorwhen runningdocker compose build && docker compose upbecause of a volume mount conflict:Root Cause
Dockerfilerunssetup_deepseek.shwhich downloads the model inside the container during builddocker-compose.ymlhas./models:/app/modelsvolume mount/app/models/with the (empty) host's./models/directoryHFValidationErrorSolution
This PR fixes the issue by enforcing proper setup order:
setup_local.shsetup_deepseek.shnow only clones source codeKey Changes
New Files Added
setup_local.sh- Pre-build setup script./models/docker compose buildbuild_and_run.sh(Linux/macOS) - All-in-one automated scriptsetup_local.shif neededCLAUDE.md- Comprehensive codebase documentationModified Files
setup_deepseek.shbuild.bat(Windows)docker compose(v2) instead of deprecateddocker-composeAll script references updated
docker-composetodocker compose(Docker CLI plugin v2)Breaking Changes
REQUIRED: Run Setup Before Building
Users must now run
setup_local.sh(orbuild_and_run.sh) before building Docker:Why This Approach?
Pros:
Cons:
Testing Performed
Tested the complete workflow from clean state:
Compatibility
docker-compose.ymlunchangedDocumentation Updates
CLAUDE.mdfor AI assisted dev workflows from other contributorsHFValidationErrordocker compose(v2)Merge Notes
This PR includes a merge of upstream changes from
mainbranch:All conflicts have been resolved while preserving both the fixes from this branch and the new features from upstream.
Checklist
docker compose(notdocker-compose)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.