Last active
May 20, 2020 08:31
-
-
Save donilan/ffa00d6a7ea500b5e29ec8cabb279ac2 to your computer and use it in GitHub Desktop.
Clean docker by cronjob
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
#!/usr/bin/env bash | |
#write out current crontab | |
crontab -l > /tmp/mycron | |
cat << EOF >> /tmp/mycron | |
# please pay atention, 168h is 7 days, which mean is it only keep the images created in 14 days, other will be removed. | |
0 0 * * * docker image prune -a --filter "until=$(date +'%Y-%m-%dT%H:%M:%S' --date='-14 days')" | |
5 0 * * * docker container prune -f | |
10 0 * * * docker volume prune -f | |
EOF | |
crontab /tmp/mycron | |
rm /tmp/mycron |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment