$ docker images -q -f dangling=true | xargs --no-run-if-empty --delim='\n' docker rmi

June 15, 2018, 1:12 a.m.penguincoder


It does not return a failing exit code if there are no images removed. It should always succeed unless there was an actual problem removing a Docker image.


This only works in the GNU version of xargs (thanks to the --no-run-if-empty), BSD does not have an equivalent that I know about.