Skip to content

Instantly share code, notes, and snippets.

@n1koo
Created March 9, 2016 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1koo/7f1399eb7d30bfeed18a to your computer and use it in GitHub Desktop.
Save n1koo/7f1399eb7d30bfeed18a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Keep last 10h of images
# Remove all containers except those that just exited
output=$( docker ps -a|egrep -v 'CONTAINER ID|seconds ago'|cut -d' ' -f1| xargs -r docker rm -v 2>&1 )
logger -t "docker-gc" "$output"
# Keep last 10h of images
output=$( docker images -a|egrep -v 'IMAGE ID|seconds ago|minute|About an hour ago| [0-9] hours ago'| tr -s ' ' | cut -d ' ' -f 3| xargs -r docker rmi -f 2>&1)
logger -t "docker-gc" "$output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment