Delete all untagged Docker images

docker rmi $(docker images -f "dangling=true" -q)

April 27, 2018stefanobaghino

Explanation

docker images outputs all images currently available.

By specifying -f "dangling=true" we restrict the list to "dangling" images (i.e. untagged).

By specifying the -q option we make the output quiet, so it prints only the image hashes.

We pass the output of $(...) to docker rmi, which removes the images with the corresponding hashes.

Limitations

If there are no untagged images, than the docker rmi command will fail, since there is nothing to remove.

Alternative one-liners

Delete all untagged Docker images

docker images -f dangling=true -q | xargs --no-run-if-empty docker rmi

June 15, 2018penguincoder