picostitch
crafting (and) JavaScript

Free Docker Disk Space - 'no space left on device'

Update: 2025-08-17 Added the buildx stuff.

The message I saw was:

 => => transferring context: 37B
------
 > [django base 1/6] FROM docker.io/library/python:latest@sha256:3b2f1......:
------
failed to solve: failed to copy: write /var/lib/docker/buildkit/content/ingest/83f8......../data: no space left on device

It had stopped the building of my docker containers. See the no space left on device error? So I needed to free up some disk space.

Reclaim Docker Build Space Disk Space

Running docker system df shows the disk usage of docker, including the build cache.

> docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
...
Build Cache     668       0         15.72GB   15.72GB

This looks a lot like it can be freed up, so I run:

> docker builder prune -a
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

WARNING! This will remove all build cache. Are you sure you want to continue? [y/N] n

Of course I click n otherwise I will fall over this tomorrow again.

Install buildx

> brew install docker-buildx

looks good,

> which docker-buildx
/opt/homebrew/bin/docker-buildx

> docker-buildx --help
Extended build capabilities with BuildKit

Usage:
  docker-buildx
  docker-buildx [command]

Available Commands:
  bake        Build from a file
  build       Start a build
  create      Create a new builder instance
  dial-stdio  Proxy current stdio streams to builder instance
  du          Disk usage
  help        Help about any command
  history     Commands to work on build records
  imagetools  Commands to work on images in registry
  ...

Reclaim Disk Space with buildx

Now getting back to the actual goal of reclaiming disk space, I run:

> docker-buildx prune -a
WARNING! This will remove all build cache. Are you sure you want to continue? [y/N] y
ID						    RECLAIMABLE	SIZE		LAST ACCESSED
hym081...               	true 	 	73.67kB   	4 months ago
p8rk5m...               	true 	 	0B        	11 months ago
ymvy66...               	true 	 	73.67kB   	3 months ago
plkijc...               	true 	 	0B        	10 months ago
j85i1e...               	true 	 	73.67kB   	2 weeks ago
58r3y4...               	true 	 	73.29kB   	6 months ago
and so on...

Total:	16.16GB

Does a lot of work and feels scary or cleansing, depending on how you look at it.

> docker system df

TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
...
Build Cache     0         0         0B        0B

From 15.72GB down to 0B, that is a lot of space reclaimed.

Of course, this has the effect that all my docker images will be rebuilt the next time I run docker-compose build, but that is fine, I run it locally for development and this kind of clean up once in a while is a good thing, I would say.

Let's see if the docker-compose build works now.
YES.

Is buildx the right way?

I have no idea, since the company behind docker is moving closer to the money and further away from the open source community, I am not sure if this is the right way to go. Do you know other tools?

Btw in case you are on a Mac there are alternatives to Docker Desktop, like Colima, which I am using happily for years already and it works flawless. Eventually I am curious about trying Apple's native container support, but did not feel like investing time into it yet.