Photo of DeepakNess DeepakNess

Preventing Docker and journal cache bloat on VPS

I have two VPS servers running Dokploy, and I noticed that even 80 GB of disk space on the servers were getting full and apps failed to deploy. The culprits were Docker cache (old images, build cache, dangling stuff from past deployments) and systemd journal logs that grow indefinitely by default.

Running the docker builder prune -a command freed ~67 GB of space on the server, so I set up a few things to automate this process:

First, I added a cron job that auto-prunes Docker every 6 hours, but only if disk usage goes above 70%:

(crontab -l 2>/dev/null; echo '0 */6 * * * [ $(df / --output=pcent | tail -1 | tr -dc 0-9) -gt 70 ] && docker system prune -af --filter "until=72h" && docker builder prune -af >> /var/log/docker-prune.log 2>&1') | crontab -

This removes unused images and build cache older than 72 hours. It doesn't touch running containers, so active deployments are safe.

Then, I vacuumed the existing journal logs down to 200MB:

journalctl --vacuum-size=200M

And finally, I capped the journal log size permanently so it never grows beyond 200MB again:

sed -i 's/#SystemMaxUse=/SystemMaxUse=200M/' /etc/systemd/journald.conf
systemctl restart systemd-journald

Applied the same setup on both servers and now I don't have to worry about cache eating up disk space over time. I know there are some drawbacks of this method, but I think the benefits outweigh them.

Comment on Mastodon

Webmentions

What’s this?