Why does apt run out of space inside a Docker build on macOS?

0
5
Asked By MellowCedar42 On

I'm building a PHP 8.5 Apache image based on Debian Trixie with Docker Desktop on macOS Tahoe. During a RUN instruction that updates and upgrades the system, installs roughly 27 packages, builds PHP extensions, and later cleans up apt, the build fails with "No space left on device" under /var/cache/apt/archives. The Mac itself has more than 100 GiB available, and Docker Desktop's builder storage limit is set to 20 GiB. However, docker buildx du reports only about 391 MB, while docker system df reports approximately 1.5 GB of build cache. I'm also performing a multi-platform build for linux/amd64 and linux/arm64. I tried pruning Docker resources, restarting Docker Desktop, splitting the package list, and deleting /var/lib/apt/lists, but apt eventually cannot even create its lock or partial directories. How can I determine which filesystem or quota is actually full, and what is the right way to fix this?

4 Answers

Answered By QuietOrbit7 On

The free space reported by macOS is not the space available inside the Linux VM used by Docker Desktop. The build runs in that VM and may also be constrained by the selected builder or its filesystem quota. Check the space from inside the build with commands such as `df -h` and `df -i`, and inspect Docker Desktop’s VM or disk-image usage rather than relying on the host’s `df` output. Increase the Docker Desktop disk limit or recreate/clean the builder if its virtual filesystem has reached its quota. A multi-platform build can consume space for both architectures.

Answered By BuildLayerFox On

`docker buildx du` only shows BuildKit’s tracked cache; it does not necessarily explain every filesystem limit encountered by a running build. Also, a single large RUN instruction can temporarily require space for downloaded archives, unpacked packages, intermediate files, PHP-extension builds, and the resulting image layer at the same time. Avoid `apt upgrade` unless it is truly needed, use `--no-install-recommends`, and clean up in the same layer after installation: remove `/var/lib/apt/lists/*`, clear `/var/cache/apt/archives/*`, and delete compiler/build artifacts. You can also use a cache mount for apt or separate build and runtime stages.

Answered By PaperComet88 On

For troubleshooting, temporarily add `RUN df -h; df -i; du -xhd1 /var /usr 2>/dev/null | sort -h` before the failing install. That will show whether bytes or inodes are exhausted and which directory is responsible. Because the build targets two platforms, test each platform separately first. If each succeeds alone but the combined build fails, the additional BuildKit and per-platform temporary storage is the likely cause.

Answered By HarborPixel19 On

The error occurring while creating `/var/cache/apt/archives/partial` and its lock confirms that the Linux filesystem available to the build is full, not that the package count itself is invalid. Since pruning did not help, check the actual builder with `docker buildx inspect --bootstrap`, verify which builder is active, and examine Docker Desktop’s disk-image allocation. If the VM has a small fixed filesystem or stale builder data, increasing the disk allocation alone may not change that existing filesystem; resetting or recreating the builder can be necessary. Recheck with `df -h` and `df -i` during the failing step to rule out inode exhaustion.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.