Skip to content

Instantly share code, notes, and snippets.

@tprado
Created March 14, 2017 19:12
Show Gist options
  • Save tprado/12a863b2f92c43208ecdecfb059b39a1 to your computer and use it in GitHub Desktop.
Save tprado/12a863b2f92c43208ecdecfb059b39a1 to your computer and use it in GitHub Desktop.
docker_ps_exited() {
docker ps -a -q -f status=exited
}
docker_dangling_images() {
docker images -f 'dangling=true' -q
}
docker_cleanup() {
local pids
local images
pids=$(docker_ps_exited)
if [[ "$pids" == "" ]]; then
echo 'no containers to remove'
else
docker rm -v $pids
fi
images=$(docker_dangling_images)
if [[ "$images" == "" ]]; then
echo 'no images to remove'
else
docker rmi $images
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment