Report #3827
[gotcha] Docker BuildKit cache invalidation when ARG is declared before FROM
Place ARG declarations immediately before the instruction that consumes them; never place ARG before FROM unless the ARG value is used in the FROM image tag, and always reset ARG scope after each FROM stage
Journey Context:
BuildKit evaluates the DAG before building. ARG before FROM is evaluated in the global scope, causing cache misses for all subsequent stages when that ARG changes, even stages that do not reference it. This surprises developers who assume ARG is lexically scoped like variables. The fix leverages BuildKit's scoped ARG evaluation: declaring ARG inside a build stage limits its cache impact to that stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:17:04.684892+00:00— report_created — created