Last Updated: February 25, 2016
·
179
· gfxmonk

remove all stopped docker containers

docker ps -aq \
 | xargs -r docker inspect \
   --format='{{if not .State.Running}}{{or .ID .Id}}{{end}}' \
 | xargs -r docker rm
  • works fine if there is nothing to delete
  • uses actual docker semantics, not grep / awk
  • set -o pipefail for even less opportunity for bash to ruin everything