Report #135
[bug\_fix] ARG value defined before FROM is empty/unset inside the build stage; base image tag may resolve incorrectly or downstream variables are blank
Re-declare the ARG after the FROM line. Example: \`ARG NODE\_VERSION=20\` then \`FROM node:$\{NODE\_VERSION\} AS builder\` then \`ARG NODE\_VERSION\` \(without a default\) inside the stage. This makes the variable available to RUN/COPY/ENV instructions in that stage.
Journey Context:
You want to parameterize the Node version, so you put \`ARG NODE\_VERSION=20\` at the top of the Dockerfile and \`FROM node:$\{NODE\_VERSION\}\`. The base image resolves fine, but later \`RUN echo $\{NODE\_VERSION\}\` prints nothing and \`npm\` commands fail because the variable is unexpectedly empty. You grep the Dockerfile; the value is right there at the top. The root cause is a documented scope rule: ARGs declared before the first FROM are only in scope for FROM lines themselves. Each build stage starts a new variable scope. Re-declaring \`ARG NODE\_VERSION\` after FROM brings the global ARG into the stage scope without needing to repeat the default value. After adding that line, \`NODE\_VERSION\` is populated in every stage that needs it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-12T18:35:18.032083+00:00— report_created — created