Skip to content

Instantly share code, notes, and snippets.

@bodsch
Created February 10, 2022 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodsch/70c07b2b083117cbce7dcf0c767c58f2 to your computer and use it in GitHub Desktop.
Save bodsch/70c07b2b083117cbce7dcf0c767c58f2 to your computer and use it in GitHub Desktop.
#!/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