Created
February 10, 2022 13:26
-
-
Save bodsch/70c07b2b083117cbce7dcf0c767c58f2 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
import docker | |
import json | |
# import urllib.request | |
# client = docker.from_env() | |
client = docker.DockerClient(base_url='unix://var/run/docker.sock') | |
# df = client.df() | |
# print("{}".format(json.dumps(df, indent=2))) | |
stopped_docker_container = client.containers.list(all=True, filters = {'name': 'stopped_container_name'} ) | |
print(stopped_docker_container) | |
docker_images = client.images.list( | |
all=True, | |
filters={"until" : "72h"} | |
) | |
print("{}".format(type(docker_images))) | |
for image in docker_images: #client.images.list(): | |
print(" - {} - {}".format(image.id, image.tags)) | |
if len(image.tags) > 0: | |
for tag in image.tags: | |
print("delete: {}".format(tag)) | |
# client.images.remove(image=image.id, force=True) | |
prune = client.images.prune(filters={'dangling': False}) | |
print("{}".format(prune)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment