Containerized Deployment of MLFlow Models with Databricks Integration
The following code utilizes gunicorn, docker, docker-compose, and mlflow to deploy models. Models are retrieved from Databricks' MLFlow registry and loaded in a dockerized gunicorn wsgi app. See Accessing MLFlow Outside of Databricks for more details.
- MLFlow
- gunicorn
- flask
- 5000
- Docker Deployment Support
- Databricks Account
- Connection to Databricks MLFlow Registry
To retrieve models from Databricks, it is highly suggested to use a service account in Databricks. See Databricks User Admin Guide for details on how to manager users.
To retrieve Databricks tokens and credentials. See Databricks-CLI Guide for more details on how to setup the databricks cli.
Please modify the values in config/web_srv.env
to provide the needed credentials
Variable | Description | Extra Details |
---|---|---|
FLASK_APP | Location of flask app code, do not modify! | |
MLFLOW_TRACKING_URI | MLFlow Tracking server URI, keep as databricks | |
DATABRICKS_HOST | URL for Databricks deployment, obtained from databricks configure |
listed as host in ~/.databrickscfg |
DATABRICKS_TOKEN | Token used for authorization/authentication against Databricks, obtained from databricks configure |
listed as password in ~/.databrickscfg |
LOGGED_MODEL | MLFlow model URI to retrieve |
Clone this repo and run the following docker-compose
command to bring up the gunicorn
server.
docker-compose up
Convert a pandas
dataframe to json
with the split
format
Post a POST
request to localhost:5000/predict
with a json payload
to predict.
In a separate terminal, run the following command to test if the gunicorn server is up. ** Note there is some startup time to connect to the MLFlow registry, so it is suggested to wait a few minutes before attempting curl the rest endpoint.
curl localhost:5000
Expected result is.
{"hello":"world"}