nuke_images.sh 644 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. # Stop any running containers
  3. running_container_ids=`docker ps -q`
  4. if test -n "$running_container_ids"
  5. then
  6. docker stop $running_container_ids
  7. fi
  8. # Delete all containers
  9. container_ids=`docker ps -a -q`
  10. if test -n "$container_ids"
  11. then
  12. docker rm -f -v $container_ids
  13. fi
  14. # Delete all images (forcefully)
  15. image_ids=`docker images -q`
  16. if test -n "$image_ids"
  17. then
  18. # Taken from: https://gist.github.com/brianclements/f72b2de8e307c7b56689#gistcomment-1443144
  19. docker rmi $(docker images | grep "$2/\|/$2 \| $2 \|$2 \|$2-\|$2_" | awk '{print $1 ":" $2}') 2>/dev/null || echo "No images matching \"$2\" left to purge."
  20. fi