MLflow Tutorial for Machine Learning in Python — Part 10: Production Checklist and Recap
The shopper project now trains, evaluates, registers and serves its model with MLflow. Before you rely on a setup like this, it has to answer four questions: which code made each model, who can reach the tracking server, what happens when its files are lost, and how it survives the next MLflow release. In this last part you'll answer all four on the series' own projects, then go through a production checklist and a recap of the whole series.
This is Part 10 of a 10-part series.
- Part 1: Install MLflow and Track Your First Experiment
- Part 2: Log Metrics Over Time and System Metrics
- Part 3: Log Artifacts and Datasets
- Part 4: Search and Filter Runs
- Part 5: Autologging and Hyperparameter Tuning with Nested Runs
- Part 6: Log, Load and Validate Models
- Part 7: Evaluate Models and Set Quality Gates
- Part 8: Register, Version and Promote Models with the Model Registry
- Part 9: Serve a Model as a REST API and in Docker
- Part 10: Production Checklist and Recap (you are here)
Every command and output on this page is real, captured while building the project.
Get the Source Code
Each archive is one of the three projects this series builds, and its own post gets it running: house prices, term deposits and shopper purchases. Every step is still shown here, for free.
What You'll Build in This Part
- a Git commit on every run: a small
code_version.pymodule, so each run records which code produced it, even though MLflow doesn't find the commit by itself here; - a check of the tracking server's network protection: what it refuses, and why;
- a backup script that copies the tracking server's database and files while the server runs;
- a restored copy of the server on a second port, to prove the backup works;
- a database upgrade, the step every future MLflow upgrade needs;
- a production checklist for everything the series built, and a recap of all ten parts.
What Production-Ready Means Here
The series runs everything on your own computer, and that doesn't change in this part. Production-ready here means four things you can check:
- Reproducible. Every model can be traced back to its code, its data and its settings. Parts 1 to 3 logged the parameters and data, and Part 6 logged each model with its environment. The missing piece is the code version.
- Protected. Only programs that should reach the tracking server can. MLflow's documentation, Protect Your Tracking Server from Network Exposure, says: "MLflow 3.5.0+ includes security middleware to protect against DNS rebinding, CORS attacks, and clickjacking."
- Recoverable. The tracking server keeps everything in two places,
mlflow.dbandmlartifacts/. A backup is only proven once you've restored it. - Upgradable. New MLflow releases can change the database's layout, its schema. MLflow's upgrade guide lists the steps.
The Example Project
The shopper project, dewiride-shopper-purchase-prediction, predicts whether an online shopping session ends in a purchase, and its champion model has been served since Part 9. The mlflow-server folder holds the tracking server from Part 1: its database mlflow.db, with the runs, models and registry of all three projects, and its files in mlartifacts/.
What This Part Costs
Nothing: MLflow, Git and Python's standard library are free. A backup takes as much disk space as the data it copies; here it was 2.4 MB for the database and 11 MB of files.
Prerequisites
- Part 9 finished: the
mlflow-serverfolder and thedewiride-shopper-purchase-predictionproject, from Part 9.
Step 1: Start the Tracking Server
Open a terminal in the mlflow-server folder and start the server, as before:
uv run mlflow server --port 8080
[MLflow] Security middleware enabled with default settings (localhost-only). To allow connections from other hosts, use --host 0.0.0.0 and configure --allowed-hosts and --cors-allowed-origins.
...
2026/11/28 13:39:43 INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
Leave it running. You saw the first line in Part 1: the server has protected itself this way all along, and Step 6 shows what that protection does. Open a second terminal in the dewiride-shopper-purchase-prediction folder for the next steps.
Step 2: See What a Run Records About Its Code
Train the model once more, the way you have since Part 6:
uv run train --run-name before-git-commit
2026/11/28 13:26:20 INFO shopper_purchase_prediction: Run before-git-commit logged the model models:/m-d10e1836469f47a6a38fb13f39ff3a63, test ROC AUC 0.9286
🏃 View run before-git-commit at: http://127.0.0.1:8080/#/experiments/3/runs/edcea13de2184325905dbdf9d058c2c7
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/3
The run's ID is the end of its link. Ask MLflow for everything it stored about the run, with your own run ID:
uv run mlflow --env-file .env runs describe --run-id edcea13de2184325905dbdf9d058c2c7
Loaded environment variables from: .env
...
"tags": {
"mlflow.user": "you",
"mlflow.source.name": "/Users/you/source/dewiride-shopper-purchase-prediction/.venv/bin/train",
"mlflow.source.type": "LOCAL",
"mlflow.runName": "before-git-commit"
}

--env-file .env makes the mlflow command read the project's .env, so it talks to your tracking server. Without it, it uses a new, empty mlflow.db in the current folder and fails with MlflowException: Run with id=… not found.
MLflow sets the tags that start with mlflow. itself. Its System Tags Reference lists one more, mlflow.source.git.commit, the "Git commit hash", set "When run from git repo". The project has been a Git repository since Part 1, but the tag isn't there. The run's page in the UI, under About this run, shows the same: a source, train, and nothing next to it.

Step 3: Find Out Why the Commit Is Missing
mlflow.source.name is the clue: the run started from .venv/bin/train, the launcher that uv run train runs. On Windows it's in .venv\Scripts; Python's venv documentation says a virtual environment has "a bin (or Scripts on Windows) subdirectory". MLflow looks for the commit in the folder of that launcher, and Git ignores the whole .venv folder. Ask Git why, with git check-ignore:
git check-ignore -v .venv
.gitignore:10:.venv .venv

Line 10 of .gitignore, from Part 1, ignores .venv. In MLflow 3.18.0, the function that finds a run's commit gives up when Git ignores the folder it starts from, so every run started through a project command has no commit. Fixed: MLflow Doesn't Record the Git Commit of a Run Started with uv run follows the cause into MLflow's code.
The project's commands should keep working as they are, so the project will read the commit itself and give it to MLflow.
Step 4: Record the Commit on Every Run
Create src/shopper_purchase_prediction/code_version.py. It starts with the project folder and the tag's name:
import logging
import subprocess
from pathlib import Path
logger = logging.getLogger("shopper_purchase_prediction")
# The project folder: src/shopper_purchase_prediction/code_version.py is two folders below it.
PROJECT_DIR = Path(__file__).resolve().parents[2]
GIT_COMMIT_TAG = "mlflow.source.git.commit"
Path(__file__).resolve().parents[2]:__file__is this file's path.parents[0]is its folder,shopper_purchase_prediction,parents[1]issrc, andparents[2]is the project folder, wherever the project lives.GIT_COMMIT_TAG: the same tag MLflow sets when it finds the commit itself, so the UI shows it in the same place.
Then the function that reads the commit:
def git_commit_tag() -> dict[str, str]:
"""The tag that records the commit the project's code is at, or no tag outside Git."""
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=PROJECT_DIR,
capture_output=True,
text=True,
check=True,
)
except OSError, subprocess.CalledProcessError:
logger.warning("Found no Git commit for the project, so the run won't record one")
return {}
return {GIT_COMMIT_TAG: result.stdout.strip()}
git rev-parse HEAD: prints the full hash of the commit the project is at (how git rev-parse HEAD works).subprocess.run(...): runs it in the project folder. Python's subprocess reference oncheck=True: "If check is true, and the process exits with a non-zero exit code, a CalledProcessError exception will be raised."capture_output=Trueandtext=Truekeep what Git prints as text inresult.stdout.except OSError, subprocess.CalledProcessError:: Git isn't installed, or the folder isn't a Git repository with a commit, as when someone unzips the project without its history. The run then goes ahead without the tag, and the warning says why. Writing two exceptions without parentheses needs Python 3.14 or newer; the project uses 3.15.result.stdout.strip(): the hash, without the line break Git ends it with.
The complete file:
"""The Git commit of the project's code, recorded on every MLflow run.
MLflow records a run's Git commit only when the script the run started from is inside the Git
repository. The project's commands start from launchers in .venv/bin, which Git ignores, so the
commit is read here and passed to mlflow.start_run as the same tag MLflow would set."""
import logging
import subprocess
from pathlib import Path
logger = logging.getLogger("shopper_purchase_prediction")
# The project folder: src/shopper_purchase_prediction/code_version.py is two folders below it.
PROJECT_DIR = Path(__file__).resolve().parents[2]
GIT_COMMIT_TAG = "mlflow.source.git.commit"
def git_commit_tag() -> dict[str, str]:
"""The tag that records the commit the project's code is at, or no tag outside Git."""
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=PROJECT_DIR,
capture_output=True,
text=True,
check=True,
)
except OSError, subprocess.CalledProcessError:
logger.warning("Found no Git commit for the project, so the run won't record one")
return {}
return {GIT_COMMIT_TAG: result.stdout.strip()}

Now give the tag to every run the project starts. mlflow.start_run takes it as tags; its reference describes the parameter as "An optional dictionary of string keys and values to set as tags on the run." In train.py, import the function next to the other project imports:
from shopper_purchase_prediction.code_version import git_commit_tag
and pass the tag where the run starts:
with mlflow.start_run(run_name=args.run_name, tags=git_commit_tag()) as run:
evaluate.py starts two runs, the evaluation and the nested baseline from Part 7, and promote.py one, from Part 8. Add the same import to both files, and the same tags=git_commit_tag() to each of these three lines:
with mlflow.start_run(run_name="baseline", nested=True, tags=git_commit_tag()):
with mlflow.start_run(run_name=args.run_name, tags=git_commit_tag()):
with mlflow.start_run(run_name=args.run_name, tags=git_commit_tag()) as run:
Step 5: Commit the Change, Then Train
The tag records the commit the code is at when the run starts, so commit the change before you train with it:
git add src/shopper_purchase_prediction
git commit -m "Record the Git commit of the code on every MLflow run"
[master 6740b92] Record the Git commit of the code on every MLflow run
4 files changed, 38 insertions(+), 4 deletions(-)
create mode 100644 src/shopper_purchase_prediction/code_version.py
git rev-parse HEAD
6740b922418ec98b77442b4c2035224964c4d3e4

Your hash is different. Train again:
uv run train --run-name with-git-commit
2026/11/28 13:30:26 INFO shopper_purchase_prediction: Run with-git-commit logged the model models:/m-2b984bc459184e68b50c7b439badcdb6, test ROC AUC 0.9286
🏃 View run with-git-commit at: http://127.0.0.1:8080/#/experiments/3/runs/c986c8dda80e443399d1b9556dde7ed9
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/3
uv run mlflow --env-file .env runs describe --run-id c986c8dda80e443399d1b9556dde7ed9
Loaded environment variables from: .env
...
"tags": {
"mlflow.user": "you",
"mlflow.source.name": "/Users/you/source/dewiride-shopper-purchase-prediction/.venv/bin/train",
"mlflow.source.type": "LOCAL",
"mlflow.source.git.commit": "6740b922418ec98b77442b4c2035224964c4d3e4",
"mlflow.runName": "with-git-commit"
}

mlflow.source.git.commit is the hash git rev-parse HEAD printed. The run's page shows the first seven characters next to the source:

With the hash, you can always get back to exactly the code that trained this model. The earlier run, before-git-commit, keeps its tags as they were.
Step 6: Check the Tracking Server's Network Protection
The server has listened on 127.0.0.1 since Part 1, so other computers can't reach it. A web page open in your browser runs on your computer, though, and the security middleware from Step 1 stands between such pages and the server. MLflow's CLI reference explains its two main settings, the allowed hosts: "DNS rebinding allows attackers to trick your browser into accessing internal services", and the allowed origins: "CORS attacks allow malicious websites to make requests to your MLflow server using your credentials." By default, the server accepts only the host names localhost and 127.0.0.1 and private network addresses, and only pages from localhost or 127.0.0.1 may call it from a browser.
Send the server a request that names another host, with curl -i so you see the status line too:
curl -i -H "Host: mlflow.example.com" http://127.0.0.1:8080/
HTTP/1.1 403 Forbidden
date: Sat, 28 Nov 2026 13:39:16 GMT
server: uvicorn
content-type: text/plain
Transfer-Encoding: chunked
Invalid Host header - possible DNS rebinding attack detected

The request reached the server, and the server refused it because of the name in its Host header. That's what stops a site whose name has been pointed at your computer. Then a request that a page on another site would send, with its address in the Origin header:
curl -i -X POST -H "Origin: https://app.example.com" -H "Content-Type: application/json" -d '{"max_results": 1}' http://127.0.0.1:8080/api/2.0/mlflow/experiments/search
HTTP/1.1 403 Forbidden
date: Sat, 28 Nov 2026 13:39:16 GMT
server: uvicorn
content-type: text/plain
access-control-allow-credentials: true
access-control-expose-headers: *
vary: Origin
Transfer-Encoding: chunked
Cross-origin request blocked

The server refused the request because of the page it came from. Finally, the headers every answer carries:
curl -I http://127.0.0.1:8080/
HTTP/1.1 200 OK
...
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-frame-options: SAMEORIGIN means only pages from the server itself may show its UI inside a frame, which is what stops clickjacking, and nosniff tells the browser not to guess what a file contains.
For this series, keep the defaults and keep the server on 127.0.0.1: it has no sign-in, so anyone who can reach it can read and change everything. When you want to open it under another name, How to Let an MLflow Server Accept Another Host Name with --allowed-hosts shows how, and when your own web app should call it, How to Let a Web App Call an MLflow Server with --cors-allowed-origins.
Step 7: Write a Backup Script
Everything the tracking server knows is in mlflow.db, and every file it keeps is in mlartifacts/. Copying mlflow.db while the server writes to it isn't safe. SQLite's own page, How To Corrupt An SQLite Database File, warns that a copy made "while it is in the middle of a transaction" "might contain some old and some new content, and thus be corrupt." SQLite's backup, which Python's sqlite3 module offers, is the safe way. Python's sqlite3 reference: "Create a backup of an SQLite database. Works even if the database is being accessed by other clients or concurrently by the same connection."
In the mlflow-server folder, create backup.py. It starts with where everything is:
SERVER_DIR = Path(__file__).resolve().parent
DATABASE = SERVER_DIR / "mlflow.db"
ARTIFACTS = SERVER_DIR / "mlartifacts"
BACKUPS = SERVER_DIR / "backups"
SERVER_DIR is the folder backup.py is in, so the script finds the files wherever you start it from. Then each backup gets a new folder, named after the time in UTC:
if not DATABASE.is_file():
print(
f"No database at {DATABASE}: keep backup.py next to mlflow.db",
file=sys.stderr,
)
return 1
target = BACKUPS / datetime.now(UTC).strftime("%Y-%m-%d_%H-%M-%S")
target.mkdir(parents=True)
The check comes first because sqlite3.connect creates a new, empty file when there's none, and backing that up would only look like a backup. The folder name, such as 2026-11-28_13-36-55, has no colons, which Windows doesn't allow in names: Microsoft's Naming Files, Paths, and Namespaces lists : among its reserved characters. Then the copy:
with (
closing(sqlite3.connect(DATABASE)) as source,
closing(sqlite3.connect(target / DATABASE.name)) as copy,
):
source.backup(copy)
if ARTIFACTS.is_dir():
shutil.copytree(ARTIFACTS, target / ARTIFACTS.name)
source.backup(copy): copies the database into the new file, as it is at one moment.closing(...): closes both connections when the block ends. Asqlite3connection's ownwithdoesn't do that; the reference: "The context manager neither implicitly opens a new transaction nor closes the connection. If you need a closing context manager, consider using contextlib.closing()."shutil.copytree: copies the artifact folder with everything in it. Python's shutil reference: "Recursively copy an entire directory tree rooted at src to a directory named dst and return the destination directory."
The complete file:
"""Back up the MLflow tracking server: its database, mlflow.db, and its artifacts, mlartifacts.
Run it with `uv run python backup.py` in the server's folder. It's safe while the server is running:
SQLite's backup copies the database as it is at one moment, even while MLflow writes to it. Each
backup goes into a new folder under backups/, named after the UTC time it started."""
import shutil
import sqlite3
import sys
from contextlib import closing
from datetime import UTC, datetime
from pathlib import Path
SERVER_DIR = Path(__file__).resolve().parent
DATABASE = SERVER_DIR / "mlflow.db"
ARTIFACTS = SERVER_DIR / "mlartifacts"
BACKUPS = SERVER_DIR / "backups"
def main() -> int:
"""Copy the database and the artifacts into backups/<time>."""
if not DATABASE.is_file():
print(
f"No database at {DATABASE}: keep backup.py next to mlflow.db",
file=sys.stderr,
)
return 1
target = BACKUPS / datetime.now(UTC).strftime("%Y-%m-%d_%H-%M-%S")
target.mkdir(parents=True)
with (
closing(sqlite3.connect(DATABASE)) as source,
closing(sqlite3.connect(target / DATABASE.name)) as copy,
):
source.backup(copy)
if ARTIFACTS.is_dir():
shutil.copytree(ARTIFACTS, target / ARTIFACTS.name)
print(f"Backed up the tracking server to {target}")
return 0
if __name__ == "__main__":
sys.exit(main())

Step 8: Back Up the Server While It Runs
Open a third terminal in the mlflow-server folder, and leave the server running:
uv run python backup.py
Backed up the tracking server to /Users/you/source/mlflow-server/backups/2026-11-28_13-36-55

The new folder holds both parts of the server:
backups/
└── 2026-11-28_13-36-55/
├── mlartifacts/
│ ├── 1/
│ ├── 2/
│ └── 3/
└── mlflow.db
mlartifacts/ keeps one folder per experiment ID: 1 is the house prices, 2 the term deposits and 3 the shoppers. Run backup.py whenever you want a backup, and copy the backups folder to another disk or another place: a backup on the same disk as the server is lost with it.
Step 9: Check That the Backup Restores
A backup you haven't restored is only a hope. Start a second tracking server from the backup, on another port, with your own backup folder's name. The live server keeps running:
uv run mlflow server --port 8081 --backend-store-uri sqlite:///backups/2026-11-28_13-36-55/mlflow.db --artifacts-destination backups/2026-11-28_13-36-55/mlartifacts
Registry store URI not provided. Using backend store URI.
[MLflow] Security middleware enabled with default settings (localhost-only). To allow connections from other hosts, use --host 0.0.0.0 and configure --allowed-hosts and --cors-allowed-origins.
...
2026/11/28 13:40:34 INFO: Uvicorn running on http://127.0.0.1:8081 (Press CTRL+C to quit)
--backend-store-uri: where the server keeps its records. The CLI reference: "URI to which to persist experiment and run data."sqlite:///followed by a path is an SQLite file, here the backup's.--artifacts-destination: where it keeps the files, "The base artifact location from which to resolve artifact upload/download/list requests", here the backup'smlartifacts.
Open http://127.0.0.1:8081/#/experiments in your browser. All three projects' experiments are there, with the times they were created:

Then open the registered model's page, http://127.0.0.1:8081/#/models/shopper-purchase-prediction. The three versions from Part 8 are there, with their quality-gate tags, and champion still points to version 2:

The records came back, and the files did too. Click Version 2, then model next to Source Model, and on the model's page click Artifacts, then MLmodel:

The server read the model's files from the backup's mlartifacts. The backup works. Close the browser tab, go to the third terminal and press Ctrl+C to stop the second server.
Step 10: Upgrade the Database Before a New MLflow Version
When a new MLflow version comes out, its database layout may have changed. MLflow's upgrade guide lists the steps: "Stop the server. Upgrade the package version in the environment. Run database migrations (if database backend is used). Restart the server." It also warns: "Schema migrations can be slow and are not guaranteed to be transactional. Always take a backup of the database before running the migration." Step 8 was that backup.
MLflow 3.18.0 is still the newest release as this is written, so there's no new version to move to. Run the migration step anyway, to see what it does to a database that's already up to date. In the first terminal, press Ctrl+C to stop the server, then:
uv run mlflow db upgrade sqlite:///mlflow.db
2026/11/28 13:39:30 INFO mlflow.store.db.utils: Updating database tables

The database was already at the newest layout for MLflow 3.18.0, so there was nothing to change. After a real upgrade, the same command migrates the tables: How to Upgrade an MLflow Tracking Database with mlflow db upgrade upgrades a database made by MLflow 3.16.0. Don't skip the step by just starting the new version: MLflow 3.18.0 migrated that older database on its own as it started, without a backup (Fixed: The MLflow Server Upgrades an Old Database on Its Own When It Starts). Start the server again:
uv run mlflow server --port 8080
The Production Checklist
Each line is something the series built, and the part that shows how.
Reproducibility
- Every run records its code version:
mlflow.source.git.commit, withcode_version.pywhen runs start from project commands (this part, Steps 4 and 5). Commit before you train. - Every run records its settings: parameters and the random seed, logged with the run (Part 1, Part 2).
- Every run records its data: the datasets it used, with a digest that changes when the data does (Part 3).
- Every model carries its contract and environment: a signature, an input example and its package versions; the training output above shows MLflow taking them from
uv.lock: "Exported 92 dependencies via uv" (Part 6). - The lock file is committed:
uv.lockpins every package, so the project installs the same versions everywhere (Part 1).
Quality
- No model goes live without passing the quality gate: evaluated against the baseline with thresholds (Part 7).
- The registry decides which model is live: the
championalias, moved only bypromoteafter the gate (Part 8). - Tuning is recorded too: every candidate of a search as a nested run (Part 5).
Security
- The tracking server stays on
127.0.0.1, with the security middleware's defaults (this part, Step 6). - The model server stays on
127.0.0.1too: it has no sign-in either (Part 9). - Models are saved with skops, which loads only the types you trust, not with pickle (Part 6).
- Settings and addresses live in
.env, which Git ignores (Part 1). - Telemetry is off, if you don't want MLflow to send anonymous usage data (Part 1).
Operations
- Back up while the server runs, and keep a copy on another disk (this part, Steps 7 and 8).
- Restore each new kind of backup on a second server before you need it (this part, Step 9).
- Back up, then upgrade the database before you start a new MLflow version (this part, Step 10).
- Clear out deleted runs with
mlflow gc(Part 4). - Watch for problems early: metrics over time and system metrics during training (Part 2).
What You Built in This Series
- Part 1: Install MLflow and Track Your First Experiment: a local tracking server, and house-price runs with parameters, metrics, tags and a figure.
- Part 2: Log Metrics Over Time and System Metrics: a forest grown in steps, with its validation curve and the computer's CPU and memory.
- Part 3: Log Artifacts and Datasets: tables, files and the datasets each run used.
- Part 4: Search and Filter Runs: finding the best run in the UI, in Python and from the command line, and cleaning up.
- Part 5: Autologging and Hyperparameter Tuning with Nested Runs: a grid search on term deposits, logged by autologging as a parent run and its children.
- Part 6: Log, Load and Validate Models: the shopper model with its signature, input example and environment, loaded back and checked.
- Part 7: Evaluate Models and Set Quality Gates:
mlflow.models.evaluate, a baseline and a gate that refuses weaker models. - Part 8: Register, Version and Promote Models with the Model Registry: versions, tags and the
championalias, moved by apromotecommand. - Part 9: Serve a Model as a REST API and in Docker: the champion as a REST API, in a model server and in a container.
- Part 10 (this part): a commit on every run, the server's protection, backups that restore, and the database upgrade.
Your Folders Now Look Like This
source/
├── mlflow-server/
│ ├── .venv/
│ ├── backups/
│ │ └── 2026-11-28_13-36-55/
│ │ ├── mlartifacts/
│ │ └── mlflow.db
│ ├── mlartifacts/
│ ├── backup.py
│ ├── mlflow.db
│ ├── pyproject.toml
│ └── uv.lock
├── dewiride-house-price-prediction/
│ └── ...
├── dewiride-term-deposit-prediction/
│ └── ...
└── dewiride-shopper-purchase-prediction/
├── .venv/
├── data/
│ └── online-shoppers.zip
├── examples/
│ ├── sessions.csv
│ └── sessions.json
├── src/
│ └── shopper_purchase_prediction/
│ ├── __init__.py
│ ├── call_api.py
│ ├── code_version.py
│ ├── config.py
│ ├── data.py
│ ├── evaluate.py
│ ├── model.py
│ ├── predict.py
│ ├── promote.py
│ ├── registry.py
│ ├── train.py
│ └── validate.py
├── .env
├── .env.example
├── .gitignore
├── .python-version
├── README.md
├── pyproject.toml
└── uv.lock
Clean Up Everything the Series Created
When you're done with the series, stop the tracking server first: go to the first terminal and press Ctrl+C. Your runs, models and registry stay in mlflow.db and mlartifacts/ until you delete them.
To remove everything the series created:
- The model image from Part 9:
docker rmi shopper-purchase-prediction:2(How to Remove a Docker Image). - The environments
mlflow models servebuilt: the folder.mlflow/envsin your home folder, with no model server running. - The California Housing download from Part 1: the folder
scikit_learn_datain your home folder. - The four folders:
mlflow-server, with its backups, and the three projects. Copy the backups somewhere else first if you want to keep your runs.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Training before committing | The run records the previous commit, which isn't the code that trained it | Commit, then train |
Running an mlflow command without --env-file .env in a project folder | It uses a new mlflow.db in that folder: MlflowException: Run with id=… not found | Add --env-file .env, and delete the stray mlflow.db |
Copying mlflow.db with a file copy while the server runs | SQLite warns that such a copy "might contain some old and some new content, and thus be corrupt" | Use backup.py, which uses SQLite's backup |
| Starting the restored server on the live server's port | Port 8080 is taken by the running server | Use another port, such as 8081 |
| Starting a new MLflow version on the old database | MLflow 3.18.0 migrated a 3.16.0 database on its own as it started, with no backup; when no tables are missing, it refuses with Detected out-of-date database schema instead | Back up, then mlflow db upgrade, then start the server |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No commit next to Source on a new run | The run didn't get the tag, or the warning Found no Git commit for the project was printed | Check that start_run has tags=git_commit_tag(), and that the project folder has at least one commit |
MlflowException: Run with id=… not found | The mlflow command didn't read .env | Fixed: "MlflowException: Run with id=… not found" When You Run an MLflow CLI Command |
Invalid Host header - possible DNS rebinding attack detected | The server was reached under a name it doesn't allow | Use 127.0.0.1 or localhost, or allow the name with --allowed-hosts |
Cross-origin request blocked from your own web app | The app's origin isn't allowed | Allow it with --cors-allowed-origins |
[Errno 48] Address already in use when starting the second server | Another program already listens on that port | Fixed: "[Errno 48] Address already in use" When You Start the MLflow Server |
FAQ
Do I have to stop the server to back it up?
No. Step 8 backed it up while it was running, and Step 9 restored that backup. Python's reference says SQLite's backup "Works even if the database is being accessed by other clients".
Do the runs from before this part get a commit?
No. Tags are written when a run starts. before-git-commit still shows only train as its source.
What about the house price and term deposit projects?
They start runs from project commands too, so they need the same change: code_version.py with their own logger name, and tags=git_commit_tag() where train.py (house prices) and tune.py (term deposits) start their runs.
Is it safe to put the tracking server on the network now?
Not as it is: it has no sign-in, so anyone who can reach it can read and change everything. The security middleware protects it from web pages in your browser, not from people. MLflow's guide to basic HTTP authentication is the place to start if you ever need to share it.
Conclusion
The series' setup now answers its four questions. code_version.py gives every run its Git commit, 6740b92 here, which MLflow didn't find on its own because runs start from launchers in the Git-ignored .venv. The tracking server refused a request with a foreign Host header and a POST from another site, both with 403. backup.py copied mlflow.db and mlartifacts while the server was running, and a second server on port 8081 showed every experiment, the champion alias and the model's files from that backup. mlflow db upgrade showed the step every future MLflow upgrade needs.
That's the whole series: ten parts, three projects and one tracking server, from your first run to a served, versioned and backed-up model. The series page lists every part in order. The complete source code of each project is on Dewiride Store: House Price Prediction, Term Deposit Prediction and Shopper Purchase Prediction, each with MLflow and scikit-learn.
Additional Resources
- Protect Your Tracking Server from Network Exposure — the security middleware and its settings.
- How to Upgrade MLflow — the upgrade steps and database migrations.
- Backend Stores — where MLflow keeps its records.
- System Tags Reference — the
mlflow.tags and when MLflow sets them. - sqlite3 Connection.backup — SQLite's backup in Python.
← Previous: Part 9: Serve a Model as a REST API and in Docker
