How to fix error exporting cache: failed to export cache in Docker

DockerINTERMEDIATEMEDIUMUpdated May 28, 2026· 248 views

This BuildKit error occurs when Docker cannot export build cache to a registry or local storage. The most common cause is using the default docker driver, which doesn't support cache export. Fix it by switching to the docker-container driver or enabling the containerd image store.

Quick fix

Fixes error exporting cache: failed to export cache

# Create a new builder with docker-container driver
docker buildx create --name mybuilder --driver docker-container --use

# Verify the builder is active
docker buildx ls

# Now run your build with cache export
docker buildx build --cache-to type=registry,ref=myregistry/myimage:cache \
  --cache-from type=registry,ref=myregistry/myimage:cache \
  -t myimage:latest .
  1. Switch to the docker-container driver
  2. Configure GitHub Actions with setup-buildx-action
  3. Enable containerd image store (Docker Desktop)
  4. Verify registry authentication for cache push
docker — error
# Create a new builder with docker-container driver
docker buildx create --name mybuilder --driver docker-container --use
# Verify the builder is active
docker buildx ls
# Now run your build with cache export
docker buildx build --cache-to type=registry,ref=myregistry/myimage:cache \
--cache-from type=registry,ref=myregistry/myimage:cache \
-t myimage:latest .
error exporting cache: failed to export cache

What this error means

The "error exporting cache: failed to export cache" message in Docker indicates that BuildKit's cache export mechanism has failed during an image build operation. This error typically appears when using the `--cache-to` flag with `docker buildx build` to export build cache layers to an external location like a container registry or local directory. BuildKit, Docker's modern build subsystem, supports exporting cache metadata and layers separately from the final image. This enables faster rebuilds by reusing previously computed layers. However, this advanced caching feature requires specific driver configurations that aren't available with Docker's default setup. The error can manifest in several forms: "cache export feature is currently not supported for docker driver", "failed to export cache: invalid incomplete links", or "error writing layer blob" messages. Each variant points to a different underlying cause, but they all relate to BuildKit's inability to complete the cache export phase of the build process.

Typical symptoms

  • docker buildx build fails with 'error exporting cache: failed to export cache'
  • CI/CD pipelines fail at the cache export step after successful image build
  • 'cache export feature is currently not supported for docker driver' error
  • GitHub Actions build-push-action fails with cache-related errors
  • 'error writing layer blob: content sha256:...: not found' during cache export
  • Build succeeds locally but fails when --cache-to is added
  • 'failed to solve: rpc error: invalid incomplete links' error
  • Cache export step hangs indefinitely in multi-stage builds

Common causes

  1. Using the default docker driver which doesn't support cache export features
  2. Missing docker buildx setup in CI/CD pipelines (GitHub Actions, GitLab CI)
  3. Registry authentication issues preventing cache layer push
  4. Corrupted cache chain from parallel builds or interrupted operations
  5. BuildKit version incompatibility with cache export type (inline, registry, local, gha)
  6. Insufficient permissions to write to the cache destination (registry or filesystem)
  7. Race conditions when multiple builds export cache simultaneously
  8. S3 or other external cache backends not properly configured or supported

How to fix "error exporting cache: failed to export cache"

1Switch to the docker-container driver

The default docker driver doesn't support cache export. Create a new builder with the docker-container driver:

bash
# Create a new builder with docker-container driver
docker buildx create --name mybuilder --driver docker-container --use

# Verify the builder is active
docker buildx ls

# Now run your build with cache export
docker buildx build --cache-to type=registry,ref=myregistry/myimage:cache \
  --cache-from type=registry,ref=myregistry/myimage:cache \
  -t myimage:latest .

The docker-container driver runs BuildKit in a container, enabling full BuildKit features including cache export.

2Configure GitHub Actions with setup-buildx-action

For GitHub Actions, add the official buildx setup action before your build step:

yaml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: user/app:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

The setup-buildx-action automatically creates a builder with the docker-container driver.

3Enable containerd image store (Docker Desktop)

Docker Desktop users can enable the containerd image store as an alternative to switching drivers:

1. Open Docker Desktop
2. Go to Settings > General
3. Enable Use containerd for pulling and storing images
4. Click Apply & Restart

Or configure it via ~/.docker/daemon.json:

json
{
  "features": {
    "containerd-snapshotter": true
  }
}

After enabling, the default docker driver will support cache export features.

4Verify registry authentication for cache push

Cache export to a registry requires push permissions. Ensure you're properly authenticated:

bash
# Login to your registry
docker login myregistry.com

# For AWS ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.us-east-1.amazonaws.com

# For Google Artifact Registry
gcloud auth configure-docker us-docker.pkg.dev

# Test push access with a small image
docker pull alpine
docker tag alpine myregistry.com/test:cache-test
docker push myregistry.com/test:cache-test

If push fails, check your registry credentials and repository permissions.

5Use inline cache for simpler setups

If registry cache export keeps failing, try inline cache which embeds cache metadata in the image itself:

bash
# Build with inline cache (works with default driver)
docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t myimage:latest .

# Push the image (cache metadata included)
docker push myimage:latest

# Later builds can use this image as cache source
docker build --cache-from myimage:latest -t myimage:latest .

Inline cache is less powerful than registry cache but more compatible. It works with the default docker driver and doesn't require separate cache storage.

6Fix invalid incomplete links errors

The "invalid incomplete links" error is a cache-chain corruption / BuildKit version bug, not a problem with your Dockerfile. It commonly appears when a stale or partially-written cache manifest is reused, often after upgrading BuildKit or interrupting a previous export. The fix is to update BuildKit and rebuild against a clean cache rather than altering your Dockerfile.

First, check your BuildKit version and update the builder to the latest BuildKit image (this bug was addressed in BuildKit v0.8.0+):

bash
# Check BuildKit version
docker buildx version

# Recreate the builder pinned to the latest BuildKit
docker buildx create --name newbuilder --driver docker-container \
  --driver-opt image=moby/buildkit:latest --use

If the error persists, the existing cache is likely corrupted. Discard it and rebuild so a fresh cache manifest is written:

bash
# Clear the local BuildKit cache for the active builder
docker buildx prune -f

# For registry/local cache, push to a NEW cache ref to abandon the corrupted chain
docker buildx build \
  --cache-to type=registry,ref=myregistry/myimage:cache-v2,mode=max \
  --cache-from type=registry,ref=myregistry/myimage:cache-v2 \
  -t myimage:latest .

Make sure all machines/CI runners sharing the cache use a compatible BuildKit version, since a mixed-version pipeline can keep re-introducing an incompatible cache manifest.

7Handle cache export timeouts and hangs

If cache export hangs (especially with multi-stage builds), try these workarounds:

bash
# Use mode=min instead of mode=max to export less cache data
docker buildx build --cache-to type=registry,ref=myimage:cache,mode=min .

# Export cache for specific stages only
docker buildx build --target builder --cache-to type=local,dest=./cache .

# Set a timeout for the build
timeout 30m docker buildx build --cache-to type=registry,ref=myimage:cache .

For persistent issues, disable cache export temporarily and investigate:

bash
# Build without cache export to confirm the build itself works
docker buildx build -t myimage:latest .

# Then test cache export separately
docker buildx build --cache-to type=local,dest=./test-cache .
8Configure local cache storage

If registry cache isn't working, use local filesystem cache:

bash
# Export cache to local directory
docker buildx build \
  --cache-to type=local,dest=./buildcache \
  --cache-from type=local,src=./buildcache \
  -t myimage:latest .

For CI/CD, mount a persistent volume or use CI-specific cache:

yaml
# GitHub Actions with local cache
- name: Build with local cache
  uses: docker/build-push-action@v5
  with:
    context: .
    cache-from: type=local,src=/tmp/.buildx-cache
    cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Move cache to prevent unbounded growth
- name: Move cache
  run: |
    rm -rf /tmp/.buildx-cache
    mv /tmp/.buildx-cache-new /tmp/.buildx-cache

Advanced notes

Understanding BuildKit cache types:

- inline: Embeds cache metadata in the image. Simple but limited - only caches the final stage.
- registry: Stores cache as a separate manifest in a registry. Full caching but requires push access.
- local: Stores cache on the filesystem. Good for local development and CI with persistent storage.
- gha (GitHub Actions): Uses GitHub's cache API. Convenient but has size limits (10GB per repo).
- s3: Stores cache in S3. Requires BuildKit v0.10+ and proper AWS credentials.

Cache mode explained:
- mode=min: Only exports layers for the final stage (default)
- mode=max: Exports all intermediate layers from all stages (slower but more cache hits)

Debugging cache export issues:

bash
# Enable BuildKit debug output
BUILDKIT_PROGRESS=plain docker buildx build --cache-to type=registry,ref=img:cache .

# Check builder logs
docker logs buildx_buildkit_mybuilder0

# Inspect cache manifest in registry
docker manifest inspect myregistry/myimage:cache

Multi-platform cache considerations:
When building multi-platform images, cache export can be tricky. Consider separate cache references per platform:

bash
docker buildx build --platform linux/amd64,linux/arm64 \
  --cache-to type=registry,ref=myimage:cache \
  --cache-from type=registry,ref=myimage:cache .

Buildx driver comparison:
| Driver | Cache Export | Use Case |
|--------|--------------|----------|
| docker | Limited (inline only without containerd) | Simple local builds |
| docker-container | Full support | CI/CD, advanced caching |
| kubernetes | Full support | K8s-based CI |
| remote | Full support | Dedicated BuildKit servers |

Known issues and workarounds:
- BuildKit issue #1981: Cache fails every second build with docker driver. Solution: use docker-container driver.
- GitHub Actions cache can fill up (10GB limit). Use move cache step to prevent unbounded growth.
- Some registries don't support OCI manifests required for cache. Check registry compatibility.

Frequently asked questions

What does "error exporting cache: failed to export cache" mean?
The "error exporting cache: failed to export cache" message in Docker indicates that BuildKit's cache export mechanism has failed during an image build operation. This error typically appears when using the --cache-to flag with docker buildx build to export build cache layers to an external location like a container registry or local directory. BuildKit, Docker's modern build subsystem, supports exporting cache metadata and layers separately from the final image.
How do I fix "error exporting cache: failed to export cache"?
This BuildKit error occurs when Docker cannot export build cache to a registry or local storage. The most common cause is using the default docker driver, which doesn't support cache export. Fix it by switching to the docker-container driver or enabling the containerd image store.
What causes "error exporting cache: failed to export cache"?
Using the default docker driver which doesn't support cache export features Missing docker buildx setup in CI/CD pipelines (GitHub Actions, GitLab CI) Registry authentication issues preventing cache layer push
Is the "error exporting cache: failed to export cache" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading