I got tired of SSH-ing into my server to clean logs and prune Docker images. So I wrote a Cron job and deployed Watchtower.
Here is the exact Bash script I use to keep my Debian VM clean automatically every morning at 6:25 AM:
#!/bin/bash # Clean logs sudo /usr/local/bin/docker-systemctl restart zabbix # Prune Docker images sudo docker system prune -af # Clean up Docker volumes sudo docker volume rm $(docker volume ls -f dangling=true -q) # Clean up unused Docker networks sudo docker network rm $(docker network ls -q -f is-isolated=true) # Reboot the server sudo shutdown -r now
With this script, I can ensure my server is always in a healthy state, even when I’m not around.
Want to learn more about automating server maintenance? Reach out to us at ShahiRaj.
Leave a Reply