Repository navigation
190 cleanup extra docker images created by mlflow - #191
Merged
Merged
Conversation
Updated the run() method in a try/finally statement that cleans the per-run image, with appropriate logging.
test_remove_run_image proves the method removes the right name and never touches the project image. test_run -> now also checks if the try/finally statement calls the cleanup and that mlflow really builds and named its image the way we expect it.
If rebuilding docker image, then remove the previous one as it will be left here as <none>:<none> after the rebuild. That's an extra case that could leave old images around.
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mikewoodward94
self-requested a review
October 5, 2026 15:31
mikewoodward94
approved these changes
Oct 5, 2026
mikewoodward94
left a comment
Collaborator
There was a problem hiding this comment.
Excellent investigative work and fix, LGTM!
(so happy this is finally fixed)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation of this bug
Closes #190.
mlops runleft Docker images behind on every run, which shows up as a growing list of<none>:<none>images (bug #190).General context on what happens: when you do
mlops runthere are always two images that are created/accessed; the per-project image, which is tagged as<name>:latest, and contains whatever the project's Dockerfile builds (mostly the OS, system and pip packages). Then, mlflow creates a second image (run-specific image rather than project), tagged as<name>:<first 7 chars of git commit>, which contains the code.After investigating here's what creates a bunch of extra images tagged as
<none>:<none>:(1) the per-run mlflow image is never removed. If you do a first run (run A) then you'll have two images,
<name>:latestand<name>:<first 7 chars of git commit>. If you do a second run on the same commit (run B), you'll end up with three images: the same<name>:latestas before, and then what happens is that the per-run mlflow image from run A has its tag moved to the per-run mlflow image of run B. Result is the per-run image of run B now has the<name>:<first 7 chars of git commit>tag, and the per-run image of run A has "lost" its tag and shows<none>:<none>.(2) The old project image persists after
rebuild_docker(-r). Rebuilding<name>:latestmoves the tag to the new image and leaves the previous one as<none>:<none>, so similar mechanism as above but on the per-project image. This happens on Docker's classic image store, e.g. Linux servers.Fixes
The changes below fix the issues so that we're always left with a single image (the project one,
<name>:latest) as there is no need to preserve the other one.(1) per-run image cleanup:
mlflow.runis now wrapped intry/finally, andremove_run_image()removes<name>:<sha7>after every run, including failed or interrupted ones.(2) rebuild cleanup: after a rebuild,
remove_replaced_image()removes the previous<name>:latestimage, but only if it has no name left.Possible issue
The
<name>:<sha7>tag format is internal to mlflow. I checked it against mlflow 2.0.0, 3.0.0, every release from 3.11.1 to 3.16.1, and currentmaster. It's identical in all of them. If a future mlflow changes it, the cleanup logs a warning, andtest_runwould fail in CI so we would notice.Testing
test_remove_run_imageandtest_remove_replaced_image.test_runnow also asserts that only<name>:latestremains after a run.