Remove Untagged Docker Images
List all images:
docker image ls
List images with a tag of <none>
:
docker image ls | grep '^<none>'
The ^<none>
will match <none>
at the start of the line and if not matched the line will not be printed.
List the hashes of images where the tag is <none>
(column number 3):
docker image ls | grep '^<none>' | awk '{print $3}'
Remove image by hash or tag:
docker image rm e894dddedf19
Remove all docker images without a tag:
docker image rm $(docker image ls | grep '^<none>' | awk '{print $3}')
...easy!
References
- Jim Hoskins this is mostly correct but in bash (a very common shell) variables will be expanded within double quotes
"
. As suchawk "{print $3}"
results inawk {print }
which is not correct. See the page for details.