Why does apt run out of space inside a Docker build when my Mac has plenty available?

0
4
Asked By MellowBirch42 On

I'm building a PHP 8.5 Apache image based on Debian Trixie with Docker Desktop on macOS. During a RUN instruction that updates, upgrades, and installs roughly 27 packages, apt fails with errors such as `You don't have enough free space in /var/cache/apt/archives/` and `No space left on device` while creating `/var/cache/apt/archives/partial` or its lock file.

The Mac itself has more than 130 GiB available, and Docker Desktop reports a disk limit of 60 GiB. The builder is configured with a 20 GB garbage-collection storage target, but `docker buildx du` reports only about 391 MB, while `docker system df` reports roughly 1.5 GB of build cache. I'm also building for both `linux/amd64` and `linux/arm64`. Pruning Docker and restarting Docker Desktop did not help. Splitting the package list and deleting `/var/lib/apt/lists/*` also still results in the same error.

The Dockerfile performs several apt operations in one build stage, including `apt update`, `apt upgrade`, two package installs, PHP extension installation, package removal, autoremove, and apt cleanup. What storage limit is actually being reached, and how can I diagnose or fix it?

3 Answers

Answered By QuietOrbit7 On

The `df` output from macOS describes the host filesystem, not the Linux filesystem used by Docker Desktop. Containers and BuildKit run inside Docker Desktop’s Linux VM, which has its own virtual disk and filesystem limits. Check the filesystem from inside a temporary container or build stage with commands such as `df -h` and `df -i`, and inspect Docker Desktop’s disk image/storage settings rather than relying on the Mac’s available space.

If the VM or its virtual disk is genuinely full, increase Docker Desktop’s allocated disk space or recreate/resize the Docker disk image. Also check inode usage with `df -i`, since “No space left on device” can mean either blocks or inodes.

Answered By CrispMaple5 On

The Dockerfile can be made less wasteful, although that alone should not be necessary for a normal 20 GB VM. Avoid `apt upgrade` in an image unless you specifically need it, because it downloads and unpacks many additional packages. Combine the required apt work into one layer and clean it in the same RUN instruction, for example:

`apt-get update && apt-get install -y --no-install-recommends ... && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*`

Use `apt-get` rather than `apt` in noninteractive Docker builds. Also note that the package list contains `zlib1g-dev` twice. These changes reduce temporary and final layer size, but if apt cannot even create its lock directory, the primary issue is still the filesystem or inode quota inside the Docker Linux VM.

Answered By LayeredPanda18 On

BuildKit’s garbage-collection setting is not the same thing as the maximum size of the Docker Desktop VM. `docker buildx du` only reports the cache visible to that builder, while the VM can also contain images, active containers, temporary build data, and data from another platform builder. Multi-platform builds may use separate intermediate layers for each architecture.

Verify which builder is active with `docker buildx ls`, inspect it with `docker buildx inspect --bootstrap`, and check Docker Desktop’s VM/disk usage. Make sure you are pruning or removing the builder that is actually performing the build. A 20 GB `defaultKeepStorage` value is a cache policy, not a guarantee that every part of the build environment has 20 GB available.

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.