Skip to content

Instantly share code, notes, and snippets.

@kbaynes
Last active January 31, 2021 15:57
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 kbaynes/9a3da6cd24fbefacf3afe0046f4380c6 to your computer and use it in GitHub Desktop.
Save kbaynes/9a3da6cd24fbefacf3afe0046f4380c6 to your computer and use it in GitHub Desktop.
Remove Docker image where tag is <none>
#!/bin/env bash
# Use: remove docker images where tag is "<none>"
# uses unix pipes
# command parts explained:
# docker images : list all of the images in Docker. Each line looks like:
# "maven 3.6.3-adoptopenjdk-11 b6e818035058 10 days ago 540MB"
# grep "<none>": show only lines that contain string <none>. Could be any string on the line.
# awk '{print $3}' : use the text processor 'awk' to split each line into columns using
# spaces and print the third colum (the docker image id, like 'b6e818035058' above)
# xargs docker image rm : use the xargs app to pass the result into the command 'docker image rm <piped value>'.
# Converts to 'docker image rm b6e818035058'
docker images | grep "<none>" | awk '{print $3}' | xargs docker image rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment