Created
March 9, 2016 07:08
-
-
Save n1koo/7f1399eb7d30bfeed18a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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