Home Docker Prune Cron Job
Post
Cancel

Docker Prune Cron Job

This is a helpful way to keep your containers from running out of space. Create a auto-prune cron job and put it in etc/cron.daily.

1
2
3
4
5
6
7
8
9
10
cat <<EOF | sudo tee /etc/cron.daily/docker-prune
#!/bin/bash

UUID=00000000-0000-0000-0000-000000000000
HOST=healthchecks.io

curl -m 5 --retry 5 https://\${HOST}/ping/\${UUID}/start
docker system prune --volumes -af
curl -m 5 --retry 5 https://\${HOST}/ping/\${UUID}
EOF
1
sudo chmod +x /etc/cron.daily/docker-prune && /etc/cron.daily/docker-prune

This also includes a ping out to healthcheck.io, which is a really handy thing to track your cron jobs. You can also self host the service.

This post is licensed under CC BY 4.0 by the author.