What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

If your CI Docker builds repeatedly download dependencies or recompile unchanged code, use BuildKit cache mounts for those tool caches and separately configure BuildKit layer-cache import and export. The “15 minutes” in the original headline is a reader scenario, not a documented typical build time or measured saving. One important catch: GitHub Actions’ BuildKit cache does not preserve cache-mount contents by default, so ephemeral runners need an additional strategy.

What BuildKit cache mounts do—and what they do not

A cache mount makes a directory available to a Dockerfile RUN instruction. Package managers and compilers can reuse files there on a later build, avoiding some repeated downloads or compilation. For example, Docker documents a Go build-cache mount at /root/.cache/go-build.

A cache mount is not the same as Docker’s ordinary instruction or layer cache. Layer caching can reuse the result of a Dockerfile instruction; a cache mount supplies reusable tool data while an instruction runs. Configure both when your build needs both kinds of reuse. Docker’s rule is explicit: “Cache mounts should only be used for better performance.” A build must remain correct if the mounted directory is empty, replaced, or removed by garbage collection. Docker’s Dockerfile reference

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

First determine whether your builder survives between CI runs

Persistent builder

When builds use the same persistent BuildKit builder, mount data can persist between invocations. It is still disposable: BuildKit may overwrite or garbage-collect it, so correctness cannot depend on it.

#1 Best Overall
Sandisk 2TB Extreme Portable SSD, Up to 1050MB/s, USB-C, USB 3.2 Gen 2, IP65 Water and Dust Resistance, Updated Firmware, External Solid State Drive, SDSSDE61-2T00-G25
  • Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
  • Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
  • Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
  • Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
  • Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C

Ephemeral GitHub-hosted runner

A fresh runner generally cannot rely on mount contents from a previous job. Exporting ordinary BuildKit cache to GitHub Actions does not automatically save the directories used by RUN --mount=type=cache. Docker documents reproducible-containers/buildkit-cache-dance as a workaround that extracts and injects mount data around the build. Its documentation example pins the action to commit 4b2444fec0c0fb9dbf175a96c094720a692ef810 and labels it v2.1.4; check the upstream project for current configuration before adopting it. Docker’s GitHub Actions cache-management guide

Add mounts for the expensive tool caches

Place a mount on the instruction that runs the package manager or compiler, and choose a target directory that the tool actually uses. Docker’s documented Go example mounts /root/.cache/go-build; its GitHub Actions cache-management example also mounts Go modules at /go/pkg/mod. A mount does not help if the relevant command writes its cache somewhere else.

Rank #2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
  • Solid state performance with up to 800MB/s read speeds in a portable drive. (Based on internal testing; performance may be lower depending on host device, interface, usage conditions and other factors. 1MB=1,000,000 bytes.)
  • Back up your content and memories on a storage solution that fits seamlessly into your mobile lifestyle.
  • Take it with you on your adventures—up to two-meter drop protection means this durable drive can take a beating. (Based on internal testing.)
  • Secure it to your belt loop or backpack for extra peace of mind thanks to the tough rubber hook.
  • From Sandisk, a brand professional photographers trust to take on assignments.

Here is the basic syntax, adapted to a Go build:

# syntax=docker/dockerfile:1
FROM golang:1.24 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod 
    go mod download
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build 
    go build -o /out/app .

The Go image version and example are illustrative; select a base image and build command appropriate to your project. The important configuration is the mount on the command that populates or consumes the cache. Since the mount is only an optimization, the commands must also work after its contents are lost.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose an ID and sharing mode deliberately

The mount ID defaults to its target path. Set an explicit id when you need to separate caches that otherwise share a target. BuildKit supports three sharing modes:

Rank #3
SSK Portable SSD 500GB External Solid State Hard Drive USB C Up to 1050MB/s
  • Capacity Display Variance: 500GB external ssd often appears as around 465GB on Windows. MacOS can show full 500 GB capacity. This is binary calculation difference and doesn’t affect SSD hard drive actual physical storage
  • 1050 MB/s Speed: Instantly access to your files with blazing-fast 10Gbps external SSD read up to 1050MB/s and write up to 1000MB/s. LED Light indicates USB SSD instant activity
  • Data Security: Solid state drives S.M.A.R.T. health diagnostics​ and adaptive TRIM optimizing data block management ensures consistent write speeds and extends the longevity of the portable SSD
  • USB-C & USB-A Cable: Both cables featuring rapid USB 3.2 Gen2, this USB SSD effortlessly bridges devices, enabling seamless cross-platform file transfers and backup between computers, smartphones, tablets and iPhone
  • Always Fast: No slowdowns for large file transfers. With SLC caching (25% of current available capacity allocated as high-speed cache), this external SSD delivers steady 10Gbps for transfers within the cache capacity
  • shared: concurrent builds may use the same cache.
  • private: concurrent builds get separate cache instances.
  • locked: another build waits until the current user releases the cache.

Choose based on the tool’s concurrency behavior. Docker’s apt example uses sharing=locked because apt needs exclusive access to its data. Docker’s Dockerfile reference

Cache apt downloads safely

Docker’s apt example disables apt’s cleanup configuration so downloaded packages remain available, then mounts both apt data directories with locked sharing:

Rank #4
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
# syntax=docker/dockerfile:1
FROM ubuntu:latest
RUN rm -f /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked 
    --mount=type=cache,target=/var/lib/apt,sharing=locked 
    apt-get update && apt-get install -y --no-install-recommends curl

This reflects Docker’s documented pattern, not a universal apt configuration. Keep package-index updates and installation together in the same instruction, and adapt package names and base image to your needs. Docker’s Dockerfile reference

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Export ordinary BuildKit cache separately

Cache mounts retain tool-specific directories; cache-from and cache-to import and export BuildKit’s reusable build cache. On GitHub Actions, Docker documents this pattern:

Best Value
Sale
Samsung T7 Portable SSD 1TB Titan Gray, USB 3.2 Gen 2, Up to 1,050MB/s
  • MADE FOR THE MAKERS: Create; Explore; Store; The T7 Portable SSD delivers fast speeds and durable features to back up any endeavor; Build your video editing empire, file your photographs or back up your blogs all in an instant
  • SHARE IDEAS IN A FLASH: Don’t waste a second waiting and spend more time doing; The T7 is embedded with PCIe NVMe technology that brings fast read and write speeds up to 1,050/1,000 MB/s¹, making it almost twice as fast as the T5
  • ALWAYS MAKE THE SAVE: Compact design with massive capacity; With capacities up to 4TB, save exactly what you need to your drive – from large working files to game data and everything in between
  • ADAPTS TO EVERY NEED: Whether using a PC or mobile phone, count on the T7 for extensive compatibility²; It’s a true team player when it comes to heavy-duty application usage or file-saving
  • HI RESOLUTION VIDEO RECORDING: Record Ultra High Resolution (4K 60fs) videos directly onto the T7 Portable SSD with your favorite camera or mobile devices; Supports iPhone 15 Pro Res 4K at 60fps video and more³
- name: Build and push
  uses: docker/build-push-action@v6
  with:
    context: .
    push: true
    tags: user/app:latest
    cache-from: type=gha
    cache-to: type=gha,mode=max

The action version here is an example, not a claim that it is the newest release. Check current Docker documentation for action and backend requirements. The GitHub Actions cache backend is experimental, subject to GitHub’s size and usage limits, and depends on the Buildx driver. With the default docker driver, Docker says the containerd image store must be enabled. Docker’s GitHub Actions cache backend documentation

Docker also documents registry-backed cache export using a separate cache reference and mode=max. Inline cache is simpler but supports only min mode. Choose the backend based on where the builder can read and write cache and what its limits allow; neither approach should be mistaken for automatic cache-mount persistence. Docker’s cache-management guide Docker’s Buildx build reference

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle read-only GitHub workflows without weakening permissions

Some GitHub events, including issue_comment and pull_request_target in the default-branch context, have read-only access to the Actions cache by default. A workflow may therefore import a cache successfully but fail when it tries to export one. For such a workflow, keep cache-from if useful and omit cache-to; populate the cache in a workflow with write access, such as a push workflow on the default branch.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not grant cache-write access broadly to untrusted workflows just to make exports succeed: Docker warns this creates cache-poisoning risk. Docker’s workflow-permissions guidance

Choose a caching approach for your CI setup

Builder and need Approach What it preserves
Persistent builder; tool cache needed Use RUN --mount=type=cache with suitable targets and sharing. Mount data may persist between invocations, but can be removed or overwritten.
Ephemeral runner; reusable build results needed Configure BuildKit cache import/export, such as GitHub Actions or registry cache. Exported BuildKit cache; this alone does not preserve cache-mount directories.
Ephemeral runner; tool cache-mount data needed too Use a documented extraction/injection workaround such as buildkit-cache-dance, or adopt a persistent-builder strategy. Mount data through the additional workaround or builder persistence; verify current implementation details.

These choices can be combined: a common CI setup exports ordinary BuildKit cache and separately handles mount directories when builds run on fresh runners. Before implementing, verify current GitHub cache limits, Buildx driver requirements, workflow permissions, and version-sensitive setup in Docker’s documentation—especially for self-managed runners, where requirements can differ or change.

Quick Recap

Bestseller No. 2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
From Sandisk, a brand professional photographers trust to take on assignments.
$188.90
SaleBestseller No. 4
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.