CI filled a 40 GB disk
My self-hosted CI runners filled their disk with 171 leftover database volumes, and the failures looked like flaky CI. The one command that shows it, and the housekeeping that comes with running your own runners.
If a CI job fails at "Set up job" and no step is marked as failed, check the free disk space on the runner before you read anything else. On October 23 that one command would have told me in seconds what I first took for flaky CI.
What it looked like
I run three self-hosted GitHub Actions runners in one container on my main lab host. The container has a 40 GB disk.
That day, jobs began failing at "Set up job," the phase before any step of mine runs. No step showed as failed, because no step had started.
A failure with no failed step reads like an infrastructure hiccup, and the natural response to a hiccup is to run the job again. Nothing in my code was implicated, since none of my code had run.
The check
Inside the runner container, df -h / reported the disk at 100 percent.
One of the three runners was in a crash loop. On startup it tried to write its own diagnostic log, could not, and exited. Then it was restarted and did the same thing. A program that has to write a log file before it can start has no way of telling you the disk is full.
Docker's volume list accounted for the space. It held 171 volumes that I had never named, and together they took 31.7 GB of the 40.
Where the volumes came from
My test jobs use a Postgres service container. The documentation describes the life of one: GitHub "creates a fresh Docker container for each service configured in the workflow" and "destroys the service container when the job completes."
The container is destroyed. On my runners, its data was left behind every time.
Two documented behaviors combine to produce that. The official Postgres image declares a volume for its data directory. Its current Dockerfile has the line VOLUME /var/lib/postgresql. When a container starts from an image like that and nobody supplies a named volume, Docker creates an anonymous one. Docker's documentation says anonymous volumes "are given a random name that's guaranteed to be unique within a given Docker host." It also says what happens to them afterward: they "persist even if you remove the container that uses them, except if you use the --rm flag when creating the container."
So each CI run started a database, received a new anonymous volume, ran its tests and finished. The container went away and the volume stayed. Across 171 of them, that works out to about 185 MB each.
Nothing here is a defect in any of the tools. The volume survives on purpose, because Docker does not delete data it cannot prove you no longer want.
The fix
I ran docker volume prune -f. The disk went from 100 percent to 21.
The command is safer than it sounds. The reference page says: "By default, it only removes anonymous volumes." It also defines what it means by unused: "Unused local volumes are those which are not referenced by any containers." A named volume is left alone unless you pass the flag for all volumes. I would still read the volume list before running it on a host that does anything besides CI.
Then I added a job that runs daily on the runner host. It prunes unused volumes and unused images, and it clears out old temporary directories that the Python test runner leaves behind.
- Job starts a Postgres serviceGitHub creates a fresh service container for each job.
- Docker creates a volumeThe Postgres image declares one, so each run gets an anonymous volume.
- Job ends and the volume staysThe container is destroyed. Its data is left behind every time.
- 171 volumes fill the diskTogether they took 31.7 GB of the 40, about 185 MB each.
- Jobs fail at Set up jobNo step shows as failed, and one runner is in a crash loop.
- Prune once, then dailydocker volume prune took the disk from 100 percent to 21.
The failures began on October 23. The runner that crashed could not write its own diagnostic log.
The housekeeping I had taken on
GitHub's page on self-hosted runners lists what you gain, including that they "don't need to have a clean instance for every job execution." It also says, further down: "Be aware that you are responsible for updating the operating system and all other software."
Those two sentences are the trade. The same documentation says that, with one exception for its smallest size, each GitHub-hosted runner "is a new virtual machine," and a machine that starts out new has none of last month's leftovers on it. A runner that persists keeps its caches, and it also keeps everything else. When I set up my own runners, I took over a cleanup job that I had never seen being done, because the hosted service does it by starting from a fresh machine. It was mine from the day the first runner registered.
The same is true of most moves from a managed service to one you run yourself. Some of the service's work, such as rotation and cleanup, was done by its design and never appeared on anyone's list. You find out about each piece when it stops being done.
What I would set up on any self-hosted runner
A disk alert well below full. Eighty percent leaves time to act. At 100 the runner cannot even log the problem.
A scheduled prune. Volumes, images and build caches, on a timer, from the first day.
A disk sized for the garbage as well as the work. Between two prunes, the disk has to hold the images plus everything the runs in that interval leave behind. Mine was holding about 185 MB per run with no limit on how many.
A known signature for runner trouble. A job that fails before its first step is telling you about the runner. Check the machine before you rerun the job. Rerunning teaches everyone to treat red as noise.
Named or disposable storage for service containers. If a job's database needs no data after the job, give the runner a way to throw it away. If it does, give the volume a name so that somebody owns it.
This is my third post since July about a disk filling up, after one on container logs and one on a backup volume. The causes were unrelated, and in each case the space went to something nobody had decided to keep. On a host that is misbehaving in a way I do not understand, df is now the first thing I run.
Sources
- https://docs.docker.com/engine/storage/volumes/
- https://docs.docker.com/reference/cli/docker/volume/prune/
- https://docs.github.com/en/actions/tutorials/use-containerized-services/use-docker-service-containers
- https://docs.github.com/en/actions/concepts/runners/self-hosted-runners
- https://docs.github.com/en/actions/concepts/runners/github-hosted-runners
- https://raw.githubusercontent.com/docker-library/postgres/master/18/bookworm/Dockerfile
Views are my own.