Docker layer cache
Cache Docker layers on RunsOn runners with Buildx type=gha, served by Magic Cache from the S3 bucket in your AWS account. No cache step to change.
Magic Cache serves the GitHub Actions cache backend of Buildx (type=gha), so Docker layers are stored in the S3 cache bucket of your stack, with no change to the cache settings. Two other places can hold layers:
| Backend | Buildx type | Notes |
|---|---|---|
| Magic Cache | type=gha | The standard GitHub cache backend, served from S3. Covered by cache isolation. |
| Ephemeral registry | type=registry | An ECR repository per stack, which also shares built images between jobs. |
| Sticky disk | none | BuildKit state on a persistent EBS disk: nothing to export or import. |
The older type=s3 backend is on Legacy caching options. For how cache-from and cache-to work, and each Buildx backend outside RunsOn, see Docker layer caching in GitHub Actions.
Availability#
Docker layer caching works on Linux runners only, with Flex and Fleet. The ephemeral ECR registry works with Fleet since v3.2.0.
Magic Cache (type=gha)#
If you already enable the Magic Cache with extras=s3-cache, your type=gha Buildx exporter is transparently redirected to S3 — no extra configuration:
jobs: docker: runs-on: runs-on=${{ github.run_id }}/runner=2cpu-linux-x64/extras=s3-cache steps: - uses: runs-on/action@v2 - uses: actions/checkout@v7 - uses: docker/setup-buildx-action@v3 - uses: docker/build-push-action@v4 with: context: "." push: false tags: test cache-to: type=gha,mode=max cache-from: type=ghaIsolation#
type=gha uses the Magic Cache protocol. When you enable Magic Cache
isolation, it receives the same repository-and-branch boundary as
actions/cache. Its first restore in each new scope is cold. See Magic Cache
scope for the rollout
settings.
Ephemeral registry (type=registry)#
Buildx can also cache layers in the stack’s ephemeral ECR registry with type=registry, which also shares built images between jobs. Give the cache its own tag:
jobs: docker: runs-on: runs-on=${{ github.run_id }}/runner=2cpu-linux-x64/extras=ecr-cache steps: - uses: runs-on/action@v2 - uses: actions/checkout@v7 - uses: docker/setup-buildx-action@v3 - uses: docker/build-push-action@v4 with: context: . push: true tags: ${{ env.RUNS_ON_ECR_CACHE }}:my-app-latest cache-from: type=registry,ref=${{ env.RUNS_ON_ECR_CACHE }}:my-app-cache cache-to: type=registry,ref=${{ env.RUNS_ON_ECR_CACHE }}:my-app-cache,mode=maxLimitations#
- Docker layer caching is only available on Linux runners.
- For a native, persistent BuildKit cache on the runner disk, see Sticky disks.