Skip to content

Parser failure on "localEnv:" in devcontainer-feature.json #1704

Description

@lesslogic

When trying to inject a host environment variable into the container like this (in devcontainer-feature.json)

"containerEnv": {
    "MY_API_KEY": "${localEnv:MY_API_KEY}"
  }

the following error is returned:

UndefinedVar: Usage of undefined variable '$localEnv' (line 23)
Dockerfile.extended:23
--------------------
  21 |     echo "_REMOTE_USER_HOME=$( (command -v getent >/dev/null 2>&1 && getent passwd 'vscode' || grep -E '^vscode|^[^:]*:[^:]*:vscode:' /etc/passwd || true) | cut -d: -f6)" >> /tmp/dev-container-features/devcontainer-features.builtin.env
  22 |     
  23 | >>> ENV MY_API_KEY="${localEnv:MY_API_KEY}"
  24 |     RUN --mount=type=bind,from=dev_containers_feature_content_source,source=opencode-psi_0,target=/tmp/build-features-src/opencode-psi_0 \
  25 |         cp -ar /tmp/build-features-src/opencode-psi_0 /tmp/dev-container-features \
--------------------
[2026-08-04T06:11:06.442Z] 
ERROR: failed to build: failed to solve: failed to process "\"${localEnv:MY_API_
_KEY}\"": unsupported modifier (:M) in substitution

The issue seems to be that the "localEnv:" substring is not getting substituted before being passed to Docker, whose parser then trips on ":M" (or apparently any other colon-letter combination). Indeed, the error message goes away by inserting a hyphen after the colon:

"containerEnv": {
    "MY_API_KEY": "${localEnv:-MY_API_KEY}"
  }

But then the value passed into the container environment is the literal string "MY_API_KEY:":

env | grep MY_API_KEY
MY_API_KEY=MY_API_KEY:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions