Report #102388
[bug\_fix] ARG declared before FROM is not available inside the build stage
Declare the ARG again after the FROM instruction, or use it only in the FROM line. ARGs defined before the first FROM are only usable as variables in FROM lines; they do not propagate into build stages unless re-declared inside the stage.
Journey Context:
My CI passed \`--build-arg NODE\_VERSION=20\` and the Dockerfile started with \`ARG NODE\_VERSION=18\` then \`FROM node:$\{NODE\_VERSION\}\`. That worked. But later in the same stage I tried \`RUN echo $NODE\_VERSION\` and got an empty string. I thought ARGs were global. After grep-ing logs I realized the variable existed only during FROM evaluation. The Dockerfile parser scopes ARGs per build stage. The fix was adding \`ARG NODE\_VERSION\` right after \`FROM node:$\{NODE\_VERSION\}\` so the value is re-introduced into that stage's environment. This is a classic scoping gotcha because shell expansion makes missing variables silently empty.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T04:47:04.262161+00:00— report_created — created