Estimate total docker build duration from layer count, cache hits and build steps.
Docker build time is driven by how many layers must actually execute versus how many are served from cache: time = layers × avg_layer_time × (1 − cache_hit_rate) ÷ parallel_factor. Ordering Dockerfile instructions so that frequently-changing steps (e.g. COPY source code) come after stable steps (e.g. installing dependencies) maximizes cache hit rate on incremental builds.
buildTime = (layers × avgLayerTime × (1 - cacheHitRate)) / parallelFactor
Order Dockerfile instructions from least to most frequently changing, copy dependency manifests (package.json, requirements.txt) before application source code, and use BuildKit's cache mounts for package manager caches.
It models BuildKit's ability to build independent multi-stage build stages concurrently, or running multiple image builds concurrently in CI. A factor of 1 means fully sequential.
Every layer must re-download dependencies, recompile, and re-execute from scratch — this is the classic 'cold cache' first build a CI runner experiences after cache eviction.
Yes — CI runners often start with cold local caches; pulling a remote cache (registry cache or BuildKit --cache-from) before building restores a meaningful cache hit rate on ephemeral runners.