Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

Your CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.

IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Build caches and old images accumulate on long-lived runners.

What I'd do →

  1. Script with the Docker SDK: containers.prune(), images.prune(filters={"dangling": True}), then remove images older than N days not in an allow-list, and api.prune_builds() for BuildKit cache.
  2. Run it as a scheduled job and log space reclaimed.
  3. Alert on disk above 80% (node exporter).
  4. Better: ephemeral runners that start clean each job.

Why → Pruning treats the symptom; ephemeral runners remove the cause.

Interview tip → Mention build cache, which docker image prune does not touch.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation