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
-
Docker Build Context Reduction & .dockerignore Audit Prompt
Audit a bloated Docker build context, identify what is being uploaded to the daemon unnecessarily, and produce a tuned .dockerignore plus COPY strategy that shrinks context and speeds builds.
-
Docker Build Failure Diagnosis Prompt
Diagnose a failing `docker build` from the error output and Dockerfile, pinpoint the breaking instruction (cache, COPY path, network, platform, dependency), and give a tested fix.
-
Registry Pull-Through Cache Design Prompt
Design a pull-through cache / registry mirror so hosts stop hitting Docker Hub rate limits, pulls get faster, and images survive upstream outages.
-
Secrets Injection & Leak-Proofing Prompt
Move secrets out of Dockerfiles, images, and env vars into runtime injection (build secrets, Docker/Swarm secrets, mounted files) and audit for baked-in credentials.
More Docker with AI prompts & error guides
Browse every Docker with AI prompt and troubleshooting guide in one place.
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.