Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created January 29, 2015 14:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ngauthier/bd7fa10e558aa0c46e71 to your computer and use it in GitHub Desktop.
Save ngauthier/bd7fa10e558aa0c46e71 to your computer and use it in GitHub Desktop.
Clean up docker containers and images
# Docker
function docker-cleanup {
# Find all containers that have exited
containers=`docker ps -a -q -f status=exited | xargs`
if [[ $containers ]]; then
# Remove exited containers
docker rm $containers
else
echo "No containers to remove"
fi
# Find all images that are not tagged
images=`docker images -a -q -f dangling=true | xargs`
if [[ $images ]]; then
# Remove untagged images
docker rmi $images
else
echo "No images to remove"
fi
# List containers and images that remain
docker ps -a
docker images -a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment