[SOLUTION] error: failed to read dockerfile

Recently, I ran into a head-scratcher while building my Docker image for an AWS Lambda function. The error message was:

>>> docker build -t web-scraper-lambda .
[+] Building 0.0s (2/2) FINISHED                                                           
 => ERROR [internal] load build definition from Dockerfile                            0.0s
 => ERROR [internal] load .dockerignore                                               0.0s
------
 > [internal] load build definition from Dockerfile:
------
------
 > [internal] load .dockerignore:
------
ERROR: failed to solve: failed to read dockerfile: failed to create lease: read-onlyf5a1eda60df65c4c39f8b

At first glance, this error seemed to point to a filesystem or permission problem—even though my host disk had plenty of free space (30GB) and the directory was writable. The problem was actually rooted deeper within Docker’s internal storage.

System Info

Apple M2, 16GB RAM on version 15.0

What I Tried

1. Disabling BuildKit

BuildKit is Docker’s modern build backend that speeds up image builds and provides better caching.
I disabled BuildKit, thinking it might be interfering with my build, by running:

export DOCKER_BUILDKIT=0
docker build -t web-scraper-lambda .

This resulted in:

ERRO[0001] Can't add file /...: read/write on closed pipe  
Error response from daemon: mkdir /var/lib/docker/tmp/docker-builder1943136018: read-only file system

2. Re-Enabling BuildKit

I then re-enabled BuildKit by resetting the variable:

export DOCKER_BUILDKIT=1
docker build -t web-scraper-lambda .

However, the build still failed with:

ERROR: failed to read dockerfile: failed to create lease: read-only file system

3. Pruning the Docker Cache

Cache pruning is a command used to remove unused data, potentially clearing corrupt or full state in Docker’s storage.
I attempted to clear Docker’s cache using:

docker system prune -af
docker builder prune -af

These commands, however, returned:

Error response from daemon: failed to prune build cache: read-only file system

Clearly, Docker’s internal storage wasn’t accepting any write operations.

4. Restarting Docker and the Host

I restarted Docker Desktop and even rebooted my machine, hoping that a fresh start would restore write access. Unfortunately, every build attempt continued to trigger the same error.

The Root Cause and Fix

After examining the issue further, I discovered that Docker’s internal disk image was nearly full—less than 1GB remained out of a total 62GB. When Docker’s internal storage is almost exhausted, it switches to a read-only mode to prevent filesystem corruption.

The Fix: I reset Docker to its system defaults. This procedure cleared all containers, images, caches, and—most importantly—restored the disk image to its full capacity:

Docker will restart. Wait a couple minutes, then open Docker again. You should see way more Disk space available (at the bottom of the screen).

Previously, this said 1GB available. After resetting system defaults, it shot back up to 57GB.
docker build -t web-scraper-lambda .

After the reset, the build completed successfully.

Summary

  • BuildKit (modern build backend):
    Disabled with export DOCKER_BUILDKIT=0 but still returned errors indicating a read-only state.
  • Cache Pruning (removing old images/containers):
    Commands like docker system prune -af failed with “read-only file system,” pointing to internal storage issues.
  • Restarting the Environment:
    Reboots and restarts did not resolve the error.
  • Diagnosis:
    Disk inspection showed that Docker’s internal disk was nearly full—under 1GB free out of 62GB.
  • Solution:
    Reset Docker to system defaults, which cleared all data and restored the internal disk, allowing builds to complete as expected.

In this case, a nearly full internal disk masquerading as a mysterious “read-only file system” error. Resetting Docker cleared the clutter and restored normal functionality.