This guide explains how to use the Docker containerization setup for the Diamond Price Predictor system.
The system includes the following containerized services:
- API Service (
api) - Flask REST API for diamond price predictions - Dashboard Service (
dashboard) - Streamlit web interface - MLflow Service (
mlflow) - ML experiment tracking server
# Build containers and start services
docker-compose up --build
# Start in detached mode (background)
docker-compose up -d --build# Start only the API service
docker-compose up api
# Start API + MLflow (without dashboard)
docker-compose up api mlflow
# Start with dashboard
docker-compose up api dashboard# Stop all services
docker-compose down
# Stop and remove volumes
docker-compose down -v
# View running services
docker-compose ps
# View service logs
docker-compose logs api
docker-compose logs dashboard
docker-compose logs mlflowWhen running, services will be available at:
-
API Service: http://localhost:5000
- Health check:
GET /health - Single prediction:
POST /predict - Batch prediction:
POST /predict/batch
- Health check:
-
Dashboard: http://localhost:8501
- Interactive web interface for predictions
-
MLflow UI: http://localhost:5001
- Experiment tracking and model registry
The containers use the following persistent volumes:
./artifacts:/app/artifacts- ML models and preprocessors./logs:/app/logs- Application logs./models:/app/models- Model files./mlruns:/mlflow/mlruns- MLflow tracking data
All services include health checks that monitor:
- API service health endpoint
- Streamlit application status
- MLflow server availability
Check health status:
docker-compose psKey environment variables for configuration:
FLASK_ENV=productionFLASK_HOST=0.0.0.0FLASK_PORT=5000PYTHONPATH=/app/src
API_URL=http://api:5000
# Use development override
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up# Default production configuration
docker-compose up -d# All services
docker-compose logs -f
# Specific service
docker-compose logs -f api
docker-compose logs -f dashboard# View resource usage
docker stats
# Service-specific stats
docker stats diamond-predictor-api
docker stats diamond-dashboard- Port conflicts: Change ports in docker-compose.yml if needed
- Build failures: Check requirements.txt and Dockerfile syntax
- Health check failures: Verify service endpoints are responding
- Volume permissions: Ensure directories are writable
# Enter running container
docker-compose exec api bash
docker-compose exec dashboard bash
# Check container status
docker-compose ps
docker-compose top
# Rebuild specific service
docker-compose build --no-cache api
docker-compose up api- Containers run with non-root user where possible
- Health checks use internal endpoints
- Environment variables for sensitive configuration
- Volume mounts are read-only where appropriate
- Integrate with CI/CD pipeline
- Add monitoring and alerting
- Configure load balancing for production
- Implement backup strategies for persistent data