docker images -f "dangling=true" -q
lists one image per row, and docker rmi
expects them to be separated by space rather than newline, so you have to join them together before calling docker rmi
if there are multiple images that need to be removed. This is the command that works for me:
docker rmi $(docker images -f "dangling=true" -q | tr "\n" " ")