docker rmi $(docker images -f "dangling=true" -q)
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.
If there are no untagged images, than the docker rmi command will fail, since there is nothing to remove.
docker images -f dangling=true -q | xargs --no-run-if-empty docker rmi