#!/bin/bash
|
|
##########################################
|
|
# docker-cleanup-non-running-images
|
|
# ------------
|
|
# Based on the amazing work of Jess Frazelle
|
|
#
|
|
# Dependencies: docker
|
|
#
|
|
# :author: Levi Olson
|
|
# :date: 31 Jan 2018
|
|
# :version: 0.0.1
|
|
##########################################
|
|
set -e
|
|
set -o pipefail
|
|
|
|
|
|
cleanup() {
|
|
mapfile -t images < <(docker images -q --no-trunc)
|
|
for c in $(docker ps -aq); do
|
|
image=$(docker inspect --format '{{.Image}}' "$c")
|
|
images=( "${images[@]/$image}" )
|
|
done
|
|
|
|
docker rmi -f "${images[@]}" 2>&1 || true
|
|
}
|
|
|
|
cleanup
|