legal-doc-masker/DOCKER_COMPOSE_README.md

4.6 KiB

Unified Docker Compose Setup

This project now includes a unified Docker Compose configuration that allows all services (mineru, backend, frontend) to run together and communicate using service names.

Architecture

The unified setup includes the following services:

  • mineru-api: Document processing service (port 8001)
  • backend-api: Main API service (port 8000)
  • celery-worker: Background task processor
  • redis: Message broker for Celery
  • frontend: React frontend application (port 3000)

Network Configuration

All services are connected through a custom bridge network called app-network, allowing them to communicate using service names:

  • Backend → Mineru: http://mineru-api:8000
  • Frontend → Backend: http://localhost:8000/api/v1 (external access)
  • Backend → Redis: redis://redis:6379/0

Usage

Starting all services

# From the root directory
docker-compose up -d

Starting specific services

# Start only backend and mineru
docker-compose up -d backend-api mineru-api redis

# Start only frontend and backend
docker-compose up -d frontend backend-api redis

Stopping services

# Stop all services
docker-compose down

# Stop and remove volumes
docker-compose down -v

Viewing logs

# View all logs
docker-compose logs -f

# View specific service logs
docker-compose logs -f backend-api
docker-compose logs -f mineru-api
docker-compose logs -f frontend

Building Services

Building all services

# Build all services
docker-compose build

# Build and start all services
docker-compose up -d --build

Building individual services

# Build only backend
docker-compose build backend-api

# Build only frontend
docker-compose build frontend

# Build only mineru
docker-compose build mineru-api

# Build multiple specific services
docker-compose build backend-api frontend celery-worker

Building and restarting specific services

# Build and restart only backend
docker-compose build backend-api
docker-compose up -d backend-api

# Or combine in one command
docker-compose up -d --build backend-api

# Build and restart backend and celery worker
docker-compose up -d --build backend-api celery-worker

Force rebuild (no cache)

# Force rebuild all services
docker-compose build --no-cache

# Force rebuild specific service
docker-compose build --no-cache backend-api

Environment Variables

The unified setup uses environment variables from the individual service .env files:

  • ./backend/.env - Backend configuration
  • ./frontend/.env - Frontend configuration
  • ./mineru/.env - Mineru configuration (if exists)

Key Configuration Changes

  1. Backend Configuration (backend/app/core/config.py):

    MINERU_API_URL: str = "http://mineru-api:8000"
    
  2. Frontend Configuration:

    REACT_APP_API_BASE_URL=http://localhost:8000/api/v1
    

Service Dependencies

  • backend-api depends on redis and mineru-api
  • celery-worker depends on redis and backend-api
  • frontend depends on backend-api

Port Mapping

  • Frontend: http://localhost:3000
  • Backend API: http://localhost:8000
  • Mineru API: http://localhost:8001
  • Redis: localhost:6379

Health Checks

The mineru-api service includes a health check that verifies the service is running properly.

Development vs Production

For development, you can still use the individual docker-compose files in each service directory. The unified setup is ideal for:

  • Production deployments
  • End-to-end testing
  • Simplified development environment

Troubleshooting

Service Communication Issues

If services can't communicate:

  1. Check if all services are running: docker-compose ps
  2. Verify network connectivity: docker network ls
  3. Check service logs: docker-compose logs [service-name]

Port Conflicts

If you get port conflicts, you can modify the port mappings in the docker-compose.yml file:

ports:
  - "8002:8000"  # Change external port

Volume Issues

Make sure the storage directories exist:

mkdir -p backend/storage
mkdir -p mineru/storage/uploads
mkdir -p mineru/storage/processed

Migration from Individual Compose Files

If you were previously using individual docker-compose files:

  1. Stop all individual services:

    cd backend && docker-compose down
    cd ../frontend && docker-compose down
    cd ../mineru && docker-compose down
    
  2. Start the unified setup:

    cd .. && docker-compose up -d
    

The unified setup maintains the same functionality while providing better service discovery and networking.