Skip to content

Instantly share code, notes, and snippets.

@donilan
Last active May 20, 2020 08:31
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 donilan/ffa00d6a7ea500b5e29ec8cabb279ac2 to your computer and use it in GitHub Desktop.
Save donilan/ffa00d6a7ea500b5e29ec8cabb279ac2 to your computer and use it in GitHub Desktop.
Clean docker by cronjob
#!/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