Report #920
[bug\_fix] An ARG defined before the first FROM is empty when used after FROM, so base-tag variables or build arguments appear unset in later instructions.
Re-declare the ARG inside each build stage where you need it \(after the FROM line\). To use it in a FROM line, declare it before that FROM; to use it inside the stage, declare it again after the FROM.
Journey Context:
You write a Dockerfile starting with \`ARG NODE\_VERSION=20\` followed by \`FROM node:$\{NODE\_VERSION\}\`. Later in the same stage you add \`RUN echo "node version is $\{NODE\_VERSION\}"\` and expect \`20\`, but the output is blank. You try \`--build-arg NODE\_VERSION=18\` and the FROM correctly uses node:18, yet the RUN still prints nothing. Searching reveals that Docker scopes ARGs per build stage; an ARG before FROM is only in scope for FROM lines and is reset after each FROM. Adding another \`ARG NODE\_VERSION\` after the FROM restores the value from the default or from \`--build-arg\`, and the echo now prints the expected version.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T14:58:30.254503+00:00— report_created — created