An inference server for iris classification using Flask with MLflow integration, containerized with Docker, designed for ML lifecycle management and deployment.
- Train, evaluate, register, and stage ML models with MLflow
- REST API for inference with live model reloading
- Dockerized app and MLflow tracking server
- Metrics endpoint with latency, status code, and endpoint statistics
- Periodic background model reload for zero downtime
- Python 3.11+ (for local dev)
- Docker & Docker Compose (for containerized deployment)
- Git (optional, for tracking SHA in MLflow)
-
Clone the repo:
git clone https://github.com/ivarunseth/iris-mlops.git cd iris-mlops
-
Create and activate virtual environment:
python3.11 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -U pip setuptools wheel pip install -r requirements.txt
-
Setup environment variables:
Create
.env
file (optional):MLFLOW_TRACKING_URI=http://localhost:5000 MLFLOW_MODEL_NAME=iris_classifier
-
Build the Docker image:
docker compose build
-
Start containers:
docker compose up
-
The MLflow UI is available at http://localhost:5000
API server available at http://localhost:5001/api/health
mlflow server --backend-store-uri sqlite:///mlflow.db --default-artifact-root ./mlflow/mlruns --host 0.0.0.0 --port 5000
python app.py
Start all services with Docker Compose:
docker compose up
Running in host system locally
python -m src.train.py
python -m src.register.py
python -m src.stage.py <promote/demote>
python -m src.evaluate.py <None/staging/production>
Run training inside the app container:
docker exec -it iris-mlops-app-1 python -m app.src/train.py
docker exec -it iris-mlops-app-1 python -m app.src/register.py
docker exec -it iris-mlops-app-1 python -m app.src/stage.py <promote/demote>
docker exec -it iris-mlops-app-1 python -m app.src/evaluate.py <None/staging/production>
This script will:
- Train models
- Register the best model to MLflow Model Registry
- Stage the best model (to
staging
orproduction
depending on config) - Evaluate models on given stage name (alias)
Send a POST request to predict endpoint:
curl -X POST http://localhost:5001/api/predict \
-H "Content-Type: application/json" \
-d '{"inputs": [{"sepal length (cm)": 5.0, "sepal width (cm)": 1.0, "petal length (cm)": 4.0, "petal width (cm)": 1.0}]}'
Same as local but using the Docker mapped port.
- Permission errors with MLflow artifacts: Ensure volume directories have correct ownership matching container UID/GID.
- Git warnings in MLflow: Install git or set
GIT_PYTHON_REFRESH=quiet
environment variable. - Model not loaded: API auto-reloads models periodically; manual reload can be implemented if needed.