Skip to content
Latchkey

How to Cache Docker Layers with the GitHub Actions Cache

With Buildx, set cache-from/cache-to to type=gha so Docker stores and restores layers via the GitHub Actions cache.

Buildx can read and write its layer cache through the native GitHub Actions cache backend. Set cache-from: type=gha and cache-to: type=gha,mode=max on docker/build-push-action and unchanged layers are skipped on the next run.

Steps

  • Set up Buildx with docker/setup-buildx-action.
  • On docker/build-push-action, add cache-from: type=gha.
  • Add cache-to: type=gha,mode=max to also export intermediate layers.

Workflow

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - uses: docker/setup-buildx-action@v3
  - uses: docker/build-push-action@v6
    with:
      context: .
      push: false
      tags: myapp:ci
      cache-from: type=gha
      cache-to: type=gha,mode=max

Gotchas

  • mode=max caches every stage (best reuse) but writes more data; mode=min only caches the final image layers.
  • The gha backend shares the same 10 GB per-repo cache budget as actions/cache, so large layer sets can evict other caches.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →