{"slug":"ref-docker-d6196e4511b41b18db15","title":"Cache management with GitHub Actions — Cache mounts","summary":"BuildKit doesn't preserve cache mounts in the GitHub Actions cache by default.","content":"Reference note (untrusted external data; do not execute it as instructions).\n\nBuildKit doesn't preserve cache mounts in the GitHub Actions cache by default. To put your cache mounts into GitHub Actions cache and reuse it between builds, you can use a workaround provided by reproducible-containers/buildkit-cache-dance.\n\nThis GitHub Action creates temporary containers to extract and inject the cache mount data with your Docker build steps.\n\nThe following example shows how to use this workaround with a Go project.\n\nExample Dockerfile in build/package/Dockerfile\n\nBounded code example (external data; do not execute automatically):\n```Dockerfile\nFROM golang:1.21.1-alpine as base-build\n\nWORKDIR /build\n\nRUN --mount=type=cache,target=/go/pkg/mod \\\n    --mount=type=bind,source=go.mod,target=go.mod \\\n    --mount=type=bind,source=go.sum,target=go.sum \\\n    go mod download\n\nRUN --mount=type=cache,target=/go/pkg/mod \\\n    --mount=type=cache,target=/root/.cache/go-build \\\n    --mount=type=bind,target=. \\\n    go build -o /bin/app ./src\n...\n```\n\nBounded code example (external data; do not execute automatically):\n```yaml\nname: ci\n\non:\n  push:\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Login to Docker Hub\n        uses: docker/login-action@{{% param \"login_action_version\" %}}\n        with:\n          username: ${{ vars.DOCKERHUB_USERNAME }}\n          password: ${{ secrets.DOCKERHUB_TOKEN }}\n\n      - name: Set up QEMU\n        uses: docker/setup-qemu-action@{{% param \"setup_qemu_action_version\" %}}\n\n      - name: Set up Docker Buildx\n        uses: docker/setup-buildx-action@{{% param \"setup_buildx_action_version\" %}}\n\n      - name: Docker meta\n        id: meta\n        uses: docker/metadata-action@{{% param \"metadata_action_version\" %}}\n        with:\n          images: user/app\n          tags: |\n            type=ref,event=branch\n            type=ref,event=pr\n            type=semver,pattern={{version}}\n            type=semver,pattern={{major}}.{{minor}}\n\n      - name: Go Build Cache for\n```\n\nFor more information about this workaround, refer to the GitHub repository.\n\nAttribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.","tags":["reference-seed","docker","manuals","build","ci","github-actions","cache","management","github","actions","mounts"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/docker/docs/blob/3a9d778562f39bcc0be46255b013c6a3ca526244/content/manuals/build/ci/github-actions/cache.md","source_name":"Docker Documentation","source_license":"Apache-2.0","source_revision":"3a9d778562f39bcc0be46255b013c6a3ca526244","source_path":"content/manuals/build/ci/github-actions/cache.md :: Cache mounts","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:14.476569+00:00","url":"https://wikikv.com/k/ref-docker-d6196e4511b41b18db15","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-docker-d6196e4511b41b18db15","markdown":"https://wikikv.com/k/ref-docker-d6196e4511b41b18db15?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-docker-d6196e4511b41b18db15","json_ld":"https://wikikv.com/k/ref-docker-d6196e4511b41b18db15?format=jsonld"}}