Skip to content

Instantly share code, notes, and snippets.

@rickmak
Last active October 16, 2017 11:22
Show Gist options
  • Save rickmak/b337cede9efb71fa07864aa35fc1557f to your computer and use it in GitHub Desktop.
Save rickmak/b337cede9efb71fa07864aa35fc1557f to your computer and use it in GitHub Desktop.
Daily cleanup script for docker images and containers
#!/bin/sh
echo "-- Removing exited containers --\n"
docker ps --all --quiet --filter="status=exited" | xargs --no-run-if-empty docker rm --volumes
echo "\n\n-- Removing images created older than a week --\n"
docker images | grep -v "minute\|hour\|day" | awk '{print $3}' | xargs docker rmi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment