Report #97156
[bug\_fix] ARG declared after FROM cannot be used in FROM, or FROM tag is literal instead of parameterized
Declare ARG before the first FROM to make it available in FROM: ARG NODE\_VERSION=20 FROM node:$\{NODE\_VERSION\}. Remember that an ARG placed after FROM only applies to that stage and must be re-declared if needed later.
Journey Context:
A team wants one Dockerfile for Node 18 and 20, so they add ARG NODE\_VERSION after the first FROM and write FROM node:$\{NODE\_VERSION\}. BuildKit ignores the ARG because it was defined after the FROM line. They read the docs and learn that FROM can consume only ARGs declared before the first FROM. They move ARG to the top, pass --build-arg NODE\_VERSION=20 on the command line, and now the base image tag is dynamic. Each subsequent stage that needs the value re-declares ARG NODE\_VERSION to inherit it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:38:33.773401+00:00— report_created — created