Report #70128
[bug\_fix] Unexpected full cache miss when an ARG value changes because ARG is declared before FROM
Keep ARGs before FROM only for selecting the base image \(e.g., \`ARG NODE\_VERSION=20\` then \`FROM node:$\{NODE\_VERSION\}\`\). Declare all other build ARGs after the FROM they affect, so changing them does not invalidate the base-image layer and every layer that follows.
Journey Context:
Your Dockerfile starts with \`ARG NODE\_VERSION=20\` followed by \`FROM node:$\{NODE\_VERSION\}\`, then a long dependency-install chain. In CI you pass \`--build-arg BUILD\_SHA=$\(git rev-parse HEAD\)\` and wonder why every CI run rebuilds from scratch. Then you learn that an ARG declared before FROM is in scope for FROM instructions; any change to that ARG changes the FROM instruction hash, which invalidates the cached base-image resolution and every downstream layer. The established fix is to move non-base ARGs after FROM, isolating their cache impact to the layers that actually use them.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:17:58.739606+00:00— report_created — created