disk usage graph

To save disk space, you need to clean old OCI/Docker images for your servers (prod and also CI/CD). In this example, you have script for podman and docker.

Why doing it ?

I use Drone Agent to build images so I can have a lot of old images.

1 image = space disk used for nothing

For example, I build big images:

quay.io/sycured/latex-builder   2.69 GB
quay.io/sycured/buildah-vfs     474 MB

When I rebuild latex-builder, it’s 2.69 GB, it’s not nothing when you have 5 or 6 old images, you lose more than 10 GB of disk space and my VM for Drone Agent is just 50 GB of disk space.

Cleaning it is required but also in prod because you lose a lot of space disk for nothing.

KISS is the best: cron

Keep It Simple Stupid, cron is the best solution to do it.

Just put the right code to /etc/cron.daily/clean_old_images and chmod +x /etc/cron.daily/clean_old_images (perfect if for root user otherwise in user crontab)

For Podman

#!/bin/bash
podman images | awk '/none/ {print $3}' | xargs podman rmi

For Docker

#!/bin/bash
docker images | awk '/none/ {print $3}' | xargs docker rmi