Page MenuHomePhabricator
Paste P8604

not-latest-docker.py
ActivePublic

Authored by thcipriani on Jun 10 2019, 7:01 PM.
Tags
None
Referenced Files
F29435391: raw.txt
Jun 10 2019, 7:01 PM
Subscribers
None
#!/usr/bin/env python
#
# Finds all docker images without the latest tag
#
# Use like:
# python not-latest-docker.py | while read img; do docker rmi "$img"; done
import subprocess
images = {}
for thing in subprocess.check_output('docker image ls --format "{{.ID}} {{.Tag}}"', shell=True).splitlines():
image, tag = thing.split(' ')
if not images.get(image):
images[image] = []
images[image].append(tag)
for image, tags in images.items():
if 'latest' in tags:
continue
print image