Skip to content

Instantly share code, notes, and snippets.

@lagner
Created November 8, 2016 16:14
Show Gist options
  • Save lagner/47a24ac63f0698d6513ee6764f97ea62 to your computer and use it in GitHub Desktop.
Save lagner/47a24ac63f0698d6513ee6764f97ea62 to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
images = 'docker images -a'.execute().text
images.tokenize('\n').eachWithIndex { line, it ->
if (it == 0) {
// first line is table header
return
}
def parts = line.tokenize(" ").collect { it.trim() }
def (rep, tag, id) = parts
if (rep != '<none>') {
def reply = System.console().readLine "remove ${id} - ${rep}:${tag}?[y to remove]: "
if (reply != 'y') {
return
}
}
def out = "docker rmi -f ${id}".execute().text
if (out?.trim()) {
print out
println ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment