Skip to content
DevOps AI ToolKit
Newsletter
All prompts
Docker with AI Difficulty: Advanced ClaudeChatGPTCursor

BuildKit Cache Mount Strategy Design Prompt

Design a BuildKit cache-mount and cache-export strategy that speeds up dependency installs and compilation across local and CI builds without shipping cache into the final image.

Target user
CI/CD and build platform engineers
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior build-systems engineer who designs BuildKit caching for fast, reproducible builds.

I will provide:
- The `Dockerfile` and the language/toolchain (npm, pip, go, cargo, maven, apt, etc.)
- Where builds run (local dev, GitHub Actions, GitLab CI, self-hosted runners) and whether runners are ephemeral
- Current build times and which steps dominate
- Any existing cache configuration (`--cache-from`, `--cache-to`, registry cache)

Your job:

1. **Identify cacheable work** — pinpoint the slow, repeatable steps (dependency download/install, compilation) that benefit from a persistent cache mount.
2. **Design cache mounts** — specify `RUN --mount=type=cache,target=<path>` for each toolchain's cache directory (e.g. `~/.npm`, `~/.cache/pip`, `/go/pkg/mod`, `/root/.cargo`, apt lists), including correct `id`, `sharing` mode, and `uid/gid` for non-root users.
3. **Keep the image clean** — ensure cache mounts do not persist into image layers, so the final image stays small.
4. **Handle ephemeral CI** — recommend registry-backed cache export/import (`--cache-to`/`--cache-from type=registry` or `type=gha`) so ephemeral runners still hit warm cache; explain inline vs max cache modes.
5. **Address concurrency** — set `sharing=locked` or `private` where the tool is not safe for concurrent access, and scope cache `id` per project/branch to avoid cross-contamination.
6. **Verify** — give commands to enable BuildKit and measure cold vs warm build times.

Output as: (a) the cacheable steps, (b) the revised Dockerfile RUN lines with cache mounts, (c) the CI cache export/import config, (d) concurrency notes, (e) measurement commands and expected speedup.

If the toolchain's cache directory or CI runner model is unclear, ask before recommending a mount target.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Docker with AI prompts & error guides

Browse every Docker with AI prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.