Created
May 12, 2021 17:50
-
-
Save barbazul/396f5f5d22776b5ffaea204571bd81b6 to your computer and use it in GitHub Desktop.
Hacky docker clean up solution for my dev environment
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
# Cleanup Docker weekly | |
### | |
# First clear all volumes that are not associated with containers | |
# This way volumes can live up to 2 weeks without use. | |
# | |
15 8 * * 1 docker volume prune | |
### | |
# Then clear all images that have not been used in last week. | |
# These can easily be recovered from Docker Hub when needed. | |
# | |
20 8 * * 1 docker image prune --force --all --filter="until=168h" | |
### | |
# Finally, clear containers not started in last week | |
# Note that volumes will not be deleted until next week cron, so if the | |
# container is recreated within the week, the data will still be available. | |
# | |
25 8 * * 1 docker container prune --force --filter="until=168h" |
I suggest adding
--force
to not ask questions during the cron run:15 8 * * 1 docker volume prune --force
Thanks for this script :)
Never happened to me, but I guess it can't hurt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suggest adding
--force
to not ask questions during the cron run:15 8 * * 1 docker volume prune --force
Thanks for this script :)