Last active
October 11, 2018 19:16
-
-
Save ps2goat/bf06ff3592d6752e433292ec257a1fda to your computer and use it in GitHub Desktop.
PowerShell script to clean up docker images from a list of images. Use `docker image prune` for the built-in functionality.
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
docker images | Select-String -Pattern ' (?<sha>\b[a-zA-Z0-9]{12})\b ' | foreach {docker rmi --force $_.Matches.Groups[1].Value} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: you may have to run this multiple times if you have child images, depending on the order they are removed.. Child images will be removed on the first run, their parents on the second run, and so on.
--force
forces removal of an image.The regex finds a 12 char sha, with a space on either side. (this may have a collision with tags that are 12 chars; projects only have a space after and should be safe.)
If a match is found, we grab the first group's (
<sha>
) value, which ignores the spaces we are looking for on either side of the group.