Skip to content
Snippets Groups Projects
Commit 496936be authored by nimrod's avatar nimrod
Browse files

Fix for removing images that have depended images.

Can't remove an image that is the base for another image. Just ignore
the error and keep the image.
parent 2fd158df
No related branches found
No related tags found
No related merge requests found
......@@ -74,9 +74,9 @@ def normalize_names(images_by_name):
return copy_of_images
def deepclean(
def deepclean( # noqa: MC0001
includes=None, excludes=None, verbose=False, dry_run=False
): # noqa: MC0001
):
"""Clean old versions of Docker images."""
client = docker.from_env()
images = {i.id: i for i in client.images.list()}
......@@ -125,7 +125,13 @@ def deepclean(
print(f"Would have removed image {Id}.")
else:
print(f"Removing image {Id}.")
try:
client.images.remove(Id)
except docker.errors.APIError as exc:
if exc.status_code == 409:
print(f"Image {Id} has descendant images.")
else:
raise exc
def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment