Skip to content

Celesca/Urina-detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Urine Detector - Docker Setup

This project uses Docker Compose to run both the frontend and backend services together.

Prerequisites

  • Docker Desktop (Windows/Mac) or Docker Engine + Docker Compose (Linux)
  • At least 4GB of available RAM
  • At least 2GB of free disk space

Quick Start

Production Deployment

  1. Clone the repository:
git clone <repository-url>
cd urina
  1. Start all services:
docker-compose up -d
  1. Access the application:

  2. Stop all services:

docker-compose down

Development Mode

For development with hot reload:

  1. Start development services:
docker-compose -f docker-compose.dev.yml up -d
  1. Access the application:

  2. Stop development services:

docker-compose -f docker-compose.dev.yml down

Services

Backend Service

  • Container: urina-backend
  • Port: 8000
  • Technology: FastAPI + Python
  • Model: PyTorch neural network for urine analysis
  • Health Check: http://localhost:8000/health

Frontend Service

  • Container: urina-frontend
  • Port: 3000 (production) / 5173 (development)
  • Technology: React + TypeScript + Tailwind CSS
  • Build Tool: Vite

Reverse Proxy (Optional)

  • Container: urina-proxy
  • Port: 80
  • Technology: Nginx
  • Purpose: Routes frontend and API requests through a single port

Docker Commands

Build and Start

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

# Start in background
docker-compose up -d

# Start specific service
docker-compose up backend

Logs and Monitoring

# View logs from all services
docker-compose logs

# View logs from specific service
docker-compose logs backend
docker-compose logs frontend

# Follow logs in real-time
docker-compose logs -f

Managing Services

# Stop all services
docker-compose down

# Stop and remove volumes
docker-compose down -v

# Restart specific service
docker-compose restart backend

# Rebuild specific service
docker-compose up --build backend

Clean Up

# Remove all containers, networks, and images
docker-compose down --rmi all

# Remove unused Docker resources
docker system prune -f

Environment Variables

Backend (.env)

PORT=8000
HOST=0.0.0.0
DEBUG=False
MODEL_PATH=models/40_epochs.pth
CORS_ORIGINS=http://localhost:3000,http://localhost:5173,http://frontend:80

Frontend

NODE_ENV=production
VITE_API_URL=http://localhost:8000

Volume Mounts

  • ./backend/models:/app/models - Model files
  • ./backend/images:/app/images - Test images
  • ./frontend:/app - Frontend source (development only)

Network Configuration

All services run on the urina-network bridge network, allowing inter-service communication.

Troubleshooting

Common Issues

  1. Port conflicts:

    • Make sure ports 80, 3000, 5173, and 8000 are not in use
    • Modify ports in docker-compose.yml if needed
  2. Memory issues:

    • Ensure Docker has enough memory allocated (4GB recommended)
    • Check Docker Desktop settings
  3. Build failures:

    • Clear Docker cache: docker system prune -f
    • Rebuild from scratch: docker-compose build --no-cache
  4. Model file missing:

    • Ensure 40_epochs.pth is in the backend/models/ directory
    • Check file permissions

Health Checks

All services include health checks:

# Check service health
docker-compose ps

# Manual health check
curl http://localhost:8000/health  # Backend
curl http://localhost:3000         # Frontend

Debugging

  1. Access container shell:
# Backend container
docker-compose exec backend bash

# Frontend container
docker-compose exec frontend sh
  1. View detailed logs:
# All services
docker-compose logs --details

# Specific service with timestamps
docker-compose logs -t backend

Development Workflow

  1. Start development environment:
docker-compose -f docker-compose.dev.yml up -d
  1. Make changes to source code (auto-reload enabled)

  2. View logs for debugging:

docker-compose -f docker-compose.dev.yml logs -f
  1. Test the application at http://localhost:5173

  2. Stop when done:

docker-compose -f docker-compose.dev.yml down

Production Deployment

For production deployment:

  1. Update environment variables in .env files
  2. Build production images:
docker-compose build
  1. Start services:
docker-compose up -d
  1. Monitor with logs:
docker-compose logs -f

Security Considerations

  • Change default ports in production
  • Use environment-specific .env files
  • Enable HTTPS with SSL certificates
  • Implement proper authentication
  • Regular security updates for base images

Performance Optimization

  • Use multi-stage builds for smaller images
  • Implement proper caching strategies
  • Monitor resource usage
  • Scale services as needed

Backup and Restore

# Backup volumes
docker run --rm -v urina_models_data:/data -v $(pwd):/backup alpine tar czf /backup/models_backup.tar.gz /data

# Restore volumes
docker run --rm -v urina_models_data:/data -v $(pwd):/backup alpine tar xzf /backup/models_backup.tar.gz -C /

About

Urina detector - AI Web application for Sp.refractometer regression in urine medical image (Collaboration with Chula University)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors