Overview
migetpacks supports three complementary caching strategies that work together to minimize build times:- Registry-based BuildKit cache (
CACHE_IMAGE) - stores build layers in a container registry - Shared package manager cache (
BUILD_CACHE_DIR) - persists dependency downloads on a shared volume - Docker layer caching - optimized COPY order in generated Dockerfiles
Registry-Based Cache (CACHE_IMAGE)
Store BuildKit cache layers in a container registry for sharing across builds, runners, and CI environments.Cache Mode
Control how much data is stored in the registry cache withCACHE_MODE:
- min (default)
- max
Caches only the final layer. Produces smaller cache images but fewer cache hits on intermediate layers.
Additional Cache Sources (CACHE_FROM)
Read from multiple cache sources (comma-separated). Useful for sharing cache across branches or teams:CACHE_FROM sources are read-only. The build always writes to CACHE_IMAGE but can read from both CACHE_IMAGE and all CACHE_FROM entries.Force Fresh Build (NO_CACHE)
Skip reading from cache while still exporting to the cache registry:NO_CACHE=true:
--no-cacheis passed to the buildCACHE_FROMsources are skipped- Cache is still exported to
CACHE_IMAGE(so subsequent builds can use it)
Insecure Registry (CACHE_REGISTRY_INSECURE)
For internal HTTP registries (e.g., a local cache registry), enable insecure mode:Shared Package Manager Cache (BUILD_CACHE_DIR)
Mount a persistent volume to cache package manager downloads across builds. This is especially effective on self-hosted runners or Kubernetes environments with ReadWriteMany (RWX) PersistentVolumeClaims.Cache Directories by Language
| Language | Cache Location | What’s Cached |
|---|---|---|
| Node.js | /cache/npm, /cache/yarn, /cache/pnpm | Package tarballs |
| Python | /cache/pip, /cache/uv | Wheel files |
| Ruby | /cache/bundler | Gem files |
| Go | /cache/go | Module sources |
| Rust | /cache/cargo | Crate sources |
| Java | /cache/maven, /cache/gradle | Dependencies |
| PHP | /cache/composer | Composer packages |
BuildKit cache mounts (
--mount=type=cache,sharing=shared) are automatically added to generated Dockerfiles for all supported languages. The sharing=shared mode allows concurrent builds to share cache without locking.Kubernetes PVC Example
Docker Layer Caching
All generated Dockerfiles use optimized COPY ordering to maximize Docker layer cache hits. This requires no configuration and works automatically.How It Works
Cache Behavior
| Scenario | Dependency Install | Build Step |
|---|---|---|
| First build | Runs | Runs |
| Source code change only | CACHED | Runs |
| Lockfile change | Runs | Runs |
| No changes | CACHED | CACHED |
- Node.js:
package.json+ lockfile copied first - Python:
requirements.txt/pyproject.tomlcopied first - Ruby:
Gemfile+Gemfile.lockcopied first - Go:
go.mod+go.sumcopied first - Rust:
Cargo.toml+Cargo.lockcopied first - Java:
pom.xml/build.gradlecopied first - .NET:
*.csproj/*.slncopied first
Combining Strategies
For optimal performance, use all three strategies together:- Registry cache: BuildKit layers cached remotely (works across machines)
- Package cache: Dependency downloads cached locally (fastest for reinstalls)
- Layer cache: Docker layer ordering optimized (fastest for source-only changes)
- Registry mirror: Base image pulls from local cache (fastest for image downloads)
Registry Mirror
UseREGISTRY_MIRROR to configure a pull-through cache for Docker Hub base images:
registry-mirrors setting, so all image pulls automatically try the mirror first before falling back to Docker Hub.