Skip to content

Instantly share code, notes, and snippets.

@cmattoon
Created January 15, 2018 22:56
Show Gist options
  • Save cmattoon/7e81b1a007169b1631948bb3098b111c to your computer and use it in GitHub Desktop.
Save cmattoon/7e81b1a007169b1631948bb3098b111c to your computer and use it in GitHub Desktop.
#!/bin/bash
# 0 * * * * /usr/local/bin/docker-cleanup.cron.sh > /var/log/docker-cleanup.log 2> /var/log/docker-cleanup.err.log
cleanup_images() {
echo "Cleaning up images"
docker rmi -f $(docker images -af dangling=true -q)
}
cleanup_containers() {
echo "Cleaning up containers"
docker rm -f $(docker ps -af status=exited -q)
}
cleanup_volumes() {
echo "Cleaning up volumes"
docker volume rm $(docker volume ls -f dangling=true -q)
}
cleanup_containers
cleanup_images
cleanup_volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment