Help / Caching
Caching and persistent storage
A runner VM serves one job. Persistent storage is a separate feature with its own scope, lifetime and charges. Review retained content before caching secrets, tokens or sensitive build outputs.
Actions cache
On Google Cloud classes, actions/cache, setup-action caches and Docker type=gha layers use the cache in the runner's region. Entries are scoped to the repository and verified Git ref; fork pull requests have separate write scopes. Existing cache actions work without a workflow rewrite.
Actions cache storage is $0.0280 per GiB-month, billed daily. Entries unused for 7 days expire. The account limit is 100 GiB, with oldest-used entries evicted first. Reads and writes in the runner's region have no additional cache transfer charge.
Docker builds
Runners start with the public images jobs pull most often already in place: postgres:16, postgres:18, pgvector/pgvector:pg16 and python:3.13.9-slim-bookworm. Pulling one of them fetches no layers while the tag is unchanged.
Every job gets a fresh VM, so a Docker build starts with no images and no layer cache unless you keep them somewhere. There are three ways, and they work with docker/build-push-action, docker buildx build and plain docker build.
| Approach | Keeps | Best for |
|---|---|---|
| Docker's data on a sticky disk | Base images, every layer and BuildKit's cache, with nothing to upload or download | Large images and frequent builds of the same Dockerfile |
type=gha cache | Layers, in the region's Actions cache | Getting started with no workflow change beyond two lines; multi-platform builds |
| BuildKit cache directory on a sticky disk | Layers, as files on the disk | Builds that need the docker-container builder, without Actions cache traffic |
Start with Docker's data on a sticky disk where the job allows it. Layer caches (type=gha, type=local, type=registry) keep the result of each step, but never the contents of RUN --mount=type=cache directories, so a step that has to run again starts with empty package and compiler caches. A sticky disk keeps both. For compiled languages and anything with an incremental build, the warm caches inside those mounts are usually the bigger win.
Keep Docker's data on a sticky disk
dr-sticky docker <key> [size-gib] stops Docker, puts /var/lib/docker and /var/lib/containerd on a sticky disk and starts Docker again. Everything Docker stores comes back on the next run: pulled base images, built images and the build cache. Use Docker's own builder (driver: docker), which keeps its cache in that directory; you need no cache-from or cache-to.
jobs:
build:
runs-on: discountRunners-2vcpu
steps:
- uses: actions/checkout@v7
- run: dr-sticky docker docker-app 60
- uses: docker/setup-buildx-action@v4
with:
driver: docker
- uses: docker/build-push-action@v7
with:
context: .
tags: app:latest
push: false
- Run it before any step that uses Docker. It refuses to run in a job with
services:orcontainer:, because those start containers before your first step; use the label below there. - Size the disk for your images plus their build cache; 40 to 100 GiB suits most repositories. To keep the build cache within the disk, add
docker builder prune -f --keep-storage 20GBafter the build. - Use one key per family of images that share layers. Images built from a common base stage, as in a monorepo, share one key so the base is built and stored once; unrelated images each get their own key so they don't push each other's cache out. Two jobs on the same key at the same time each start from the same save, and the last to finish is kept.
- The first build on a restored disk reads its blocks from the snapshot as it goes, so it is a little slower than later steps in the same job; it is still much faster than pulling and rebuilding.
- Pushing works as usual: log in to your registry and set
push: true. The built image also stays on the disk, so if each run builds a large image under a new tag, remove that tag after the push (docker rmi) to keep the disk from filling with old images. - Don't use
setup-buildx-action's defaultdocker-containerdriver with this approach: that builder keeps its cache inside a container made for the run, which is not reused.
From the runner label
Add /docker=<key> to the runner label and the disk is mounted before the job starts, before any services: or container: container. You need no dr-sticky step, and service images such as a database come back already pulled.
jobs:
test:
runs-on: discountRunners-2vcpu/docker=test-images
services:
postgres:
image: postgres:18
steps:
- uses: actions/checkout@v7
- run: docker compose build
Keys in the label are 1 to 64 lowercase letters, digits, dots, dashes or underscores. The disk is 40 GiB, or the size of the last save if larger; use the step form for another size. The job's log says under "Set up runner" whether the disk was mounted. A job that can't get its disk goes on with an empty Docker cache. A job with this label always gets a runner made for it, never one started ahead of time, so it may take a little longer to start.
Use the type=gha cache
BuildKit's GitHub Actions cache backend works unchanged and stores layers in the Actions cache in the runner's region. Base images are still pulled each run, from our Docker Hub mirror in the same region.
- uses: docker/setup-buildx-action@v4
- uses: docker/build-push-action@v7
with:
context: .
tags: app:latest
push: false
cache-from: type=gha,scope=app
cache-to: type=gha,mode=max,scope=app,ignore-error=true
mode=max keeps the layers of every stage, not just the final one. ignore-error=true keeps a build going when the cache refuses a write, as it does for a run whose branch we have not yet confirmed with GitHub; the next run saves instead. Give each image its own scope. Cached layers count toward the account's Actions cache limit and price below.
Keep BuildKit's cache directory on a sticky disk
If you need the docker-container builder, for example for multi-platform builds, keep its cache as files on a sticky disk. BuildKit adds to a local cache without removing old layers, so write to a new directory and swap it in after the build.
- run: dr-sticky mount buildkit-app "$RUNNER_TEMP/buildkit" 40
- uses: docker/setup-buildx-action@v4
- uses: docker/build-push-action@v7
with:
context: .
tags: app:latest
push: false
cache-from: type=local,src=${{ runner.temp }}/buildkit/cache
cache-to: type=local,mode=max,dest=${{ runner.temp }}/buildkit/cache-new
- run: |
rm -rf "$RUNNER_TEMP/buildkit/cache"
mv "$RUNNER_TEMP/buildkit/cache-new" "$RUNNER_TEMP/buildkit/cache"
A registry cache (type=registry) also works as usual if you already push to your own registry.
Get the most from the cache
Most runs change some code and leave dependencies alone, so tune for that case, not for rebuilding an unchanged commit.
- Copy dependency manifests before the source. A change re-runs its own step and every step after it. Copy the lockfile, install, then copy the rest, so a code change leaves the install step cached. Final images are identical either way.
- Give package managers and compilers a cache mount. With Docker's data on a sticky disk, these directories come back on every run, so a step that runs again only does the new work.
- Prune caches that only grow. Go trims its own build cache. Cargo's
target/, pip, npm, pnpm and Bazel caches keep every version they have seen. If a disk fills, rundocker builder prune -f --keep-storage 20GB, or start fresh by changing the key or deleting it on the Storage page.
FROM node:22-slim
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci
COPY . .
RUN npm run build
The same pattern works for other stacks: go.mod and go.sum with mounts on /root/.cache/go-build and /go/pkg/mod, Cargo.toml and Cargo.lock with a mount on /usr/local/cargo/registry, and requirements.txt with a mount on /root/.cache/pip.
Sticky disks
dr-sticky mount <key> <path> [size-gib]
dr-sticky docker <key> [size-gib]
runs-on: <label>/docker=<key>
A sticky disk keeps a directory between a repository's runs, for dependency trees, build outputs and Docker data too large to move through actions/cache quickly. dr-sticky mount mounts a disk at <path>, restored from the last save of <key> or blank the first time (20 GiB unless you give a size; if the save cannot be restored within a minute, the job gets a blank disk rather than failing), and the disk is saved when the job finishes. dr-sticky docker does the same for Docker's data directory, as above.
- run: dr-sticky mount node-modules ./node_modules 20
- run: npm ci --prefer-offline
- Keys are 1 to 128 letters, digits, dots, dashes or underscores, and belong to the repository.
- A run restores its own branch's last save, else the default branch's, and saves only to its own branch. Pull requests from forks save to a separate scope.
- A disk is saved only if nothing still holds it open when the job ends; a process left running in it, such as a background server, means it is released unsaved and the log says so.
- Saves that are not used for 7 days expire. Up to 3 disks per job of up to 100 GiB each.
- Sticky disks are available on Google Cloud classes.
Attached disk time and saved snapshots are charged separately; see current storage prices and limits. The Storage page lists each saved key and lets you delete it.
Repository images and snapshots
When enabled, a repository image preinstalls dependencies from its image recipe. A snapshot runner can retain the disk left by a successful private default-branch job. Job-written files can persist, including credentials your own steps wrote. Neither feature turns a VM into a shared multi-job runner; later jobs receive new VMs from the saved image.
Deletion
The Storage page lists retained resources and accepts deletion requests. Resource deletion is asynchronous; a request and completed deletion are distinct. Recoverable provider copies and backups follow separate retention controls. The privacy policy describes the current early-access retention limitations.
Screenshots and videos in Help are a demonstration rebuilt from our own benchmark jobs. The jobs, steps, run times and charges are real; queue waits and the CPU, memory, disk and network graphs in them are illustrative, not measurements.