The very personal dotfiles of Levi Olson.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
551 B

6 years ago
  1. #!/bin/bash
  2. ##########################################
  3. # docker-cleanup-non-running-images
  4. # ------------
  5. # Based on the amazing work of Jess Frazelle
  6. #
  7. # Dependencies: docker
  8. #
  9. # :author: Levi Olson
  10. # :date: 31 Jan 2018
  11. # :version: 0.0.1
  12. ##########################################
  13. set -e
  14. set -o pipefail
  15. cleanup() {
  16. mapfile -t images < <(docker images -q --no-trunc)
  17. for c in $(docker ps -aq); do
  18. image=$(docker inspect --format '{{.Image}}' "$c")
  19. images=( "${images[@]/$image}" )
  20. done
  21. docker rmi -f "${images[@]}" 2>&1 || true
  22. }
  23. cleanup