Skip to content

dev_container: Expand bare $VAR in addition to ${VAR} in Dockerfiles#59280

Open
tnayuki wants to merge 2 commits into
zed-industries:mainfrom
tnayuki:fix/dev-container-bare-dollar-expansion
Open

dev_container: Expand bare $VAR in addition to ${VAR} in Dockerfiles#59280
tnayuki wants to merge 2 commits into
zed-industries:mainfrom
tnayuki:fix/dev-container-bare-dollar-expansion

Conversation

@tnayuki

@tnayuki tnayuki commented Jun 14, 2026

Copy link
Copy Markdown

When expanding build args in a dev container Dockerfile, only the braced
${VAR} form was substituted. The bare $VAR form — which is valid Docker
syntax and common in real-world Dockerfiles — was passed through verbatim.

For example, the Rails dev container images use:

ARG RUBY_VERSION=3.4.4
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION

This left $RUBY_VERSION unexpanded, so the subsequent docker inspect /
build ran against the literal string ruby:$RUBY_VERSION and failed with
an invalid reference format.

This adds expand_dockerfile_var, which substitutes both ${VAR} and bare
$VAR. Bare $KEY is only replaced when it is not immediately followed by
a word character, so expanding $RUBY_VERSION does not partially consume
$RUBY_VERSION2.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed dev container Dockerfiles not expanding build args written in the bare $VAR form

Dockerfiles commonly use the bare form \$VAR alongside the braced \${VAR}
form (e.g. `FROM ruby:\$RUBY_VERSION`). The expansion loop only handled
the braced form, so bare references were passed through verbatim, causing
`docker inspect` to fail with the literal string instead of the resolved
value.

Add `expand_dockerfile_var` which handles both forms. Bare \$KEY is
replaced only when not immediately followed by a word character, so
\$RUBY_VERSION2 is not consumed when expanding \$RUBY_VERSION.

Signed-off-by: Toru Nayuki <tnayuki@icloud.com>
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 14, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant