Skip to content

Instantly share code, notes, and snippets.

@mikefarah
mikefarah / cleanup_old_docker_images.sh
Last active October 5, 2016 21:39
Only remove old docker images and containers to maintain a cache
#!/bin/bash
set -e
docker_image=$1 # e.g something.com/my-image
version=$2 || "latest"
docker_url="$docker_image:$version"
running_containers=$(docker ps -a -f "ancestor=${docker_url}" -q)
docker stop $running_containers || echo 'no running containers'