Last active
October 27, 2021 14:53
-
-
Save blackandred/3b90877b944887949ad30cc22026502c to your computer and use it in GitHub Desktop.
Ansible + Docker: Clean up unused, old containers and images to free up the disk space
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
# | |
# Created for free for the anarchist movement around the world. | |
# See iwa-ait.org, zsp.net.pl, wolnosciowiec.net | |
# | |
- name: Schedule a clean up for Docker images | |
become: yes | |
cron: | |
name: "docker-clean-up-images" | |
minute: "0" | |
hour: "22" | |
job: "docker rmi $(docker images | awk '/^<none>/ { print $3 }') 2> /dev/null" | |
day: "10" | |
- name: Schedule a clean up for Docker unused containers | |
become: yes | |
cron: | |
name: "docker-clean-up-containers" | |
minute: "0" | |
hour: "22" | |
job: "docker ps --filter 'status=exited' | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm 2> /dev/null" | |
day: "5" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment