vscode-remote-release
vscode-remote-release copied to clipboard
devcontainer.json doesn't resolve custom localEnv variable on macOS
- VSCode Version: 1.77.3
- Local OS Version: macOS 13.3.1
- Remote Extension/Connection Type: Containers
Im working behind a corporate proxy, which is again proxied through a local instance of proxydetox
So on my local machine the correct proxy is: http://127.0.0.1:3128
Accessing it from within docker means setting the proxy to http://host.docker.local
To include this into my DevContainer build i have a custom ENV-variable called VSCODE_DEVCONTAINER_PROXY and my devcontainer.json looks basically like this (reduced for brevity):
{
"build": {
"dockerfile": "Dockerfile",
"args": {
"HTTP_PROXY": "${localEnv:VSCODE_DEVCONTAINER_PROXY}",
"HTTPS_PROXY": "${localEnv:VSCODE_DEVCONTAINER_PROXY}",
"http_proxy": "${localEnv:VSCODE_DEVCONTAINER_PROXY}",
"https_proxy": "${localEnv:VSCODE_DEVCONTAINER_PROXY}"
}
}
}
The variable is exported in ~/.bashrc, ~/.bash_profile, ~/.profile and also ~/.config/fish/config.fish
I expect VSCode to pickup this localEnv and then pass it to the --build-args, but as you can see in the log the variable HTTP_PROXY etc. are empty.
I also tried to add them directly in VCCode Settings but without success.

I also tried to use another default variable like ${localEnv:PATH} (which is obviously the wrong variable) to check if localEnv is faulty in general but this resolved properly.
I even used ${localEnv:PATH} which resolves properly but has the wrong value (http://127.0.0.1:3128)
- Logs:
The only interesting line in the logs is this one, Here the build-args
HTTP_PROXYetc. are empty.
[2023-04-26T10:08:59.957Z] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/l3/bgmsx_jx1811csbpk87m58ph0000gn/T/devcontainercli/container-features/0.35.0-1682503739920/Dockerfile-with-features -t vsc-***-d6151ecda705124662c41d5272a5f10e0b05ff9fa14b91ece652d96c06cf157d --target dev_containers_target_stage --build-arg HTTP_PROXY= --build-arg HTTPS_PROXY= --build-arg http_proxy= --build-arg https_proxy= --build-context dev_containers_feature_content_source=/var/folders/l3/bgmsx_jx1811csbpk87m58ph0000gn/T/devcontainercli/container-features/0.35.0-1682503739920 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /Users/Q278134/Projekte/BMW/SF.D/projects/Infrastruktur/pcmasfd-gen6-iac/.devcontainer
I found a similar issue: https://github.com/microsoft/vscode-remote-release/issues/3456 But none of the solutions proposed here works.
Steps to Reproduce:
- Define a custom env-variable
- Pass it as build-arg to the
devcontainer.json - It will be empty, no matter what's value it currently has locally
This works properly on Windows machines, so it seems to be a Mac specific problem.
Having exactly the same issue even when no corporate proxies involved.
OS: macOS 13.2.1 VSCode: 1.78.1
@iLem0n my issue resolved after rebooting the OS.
I am experiencing this issue as well on Mac.
- VSCode Version: 1.84.2
- Mac OS Version: 14.1.1
As @iLem0n reported, none of the variables in ~/.bashrc, ~/.zshrc, ~/.bash_profile, ~/.zsh_profile, ~/.bashenv, ~/.profile, etc are able to pass into my dev container when I use ${localEnv:FOO}. I have tried using build args, containerEnv, and remoteEnv to pass in the variables, but none of them worked.
What did work was setting terminal.integrated.env.linux, because the environment variables that I set are in the resulting Linux shell. However, they were empty during the container build and the execution of post-install scripts through the postCreateCommand.
I am also seeing this problem. What exactly are the env variables that are available in localEnv when the host is macOS with zsh shell?
UPDATE: turns out, I just had to restart VS code, then it picked up the env vars.
I'm also experiencing this issue on mac using e.g
"DOCKER_DEFAULT_PLATFORM": "${localEnv:DOCKER_DEFAULT_PLATFORM}"
I have the same issue on Windows. Referencing ${localEnv:HOME} in the mount section of the devcontianer.json is not resolved all the time. Sometimes it works, sometimes not. Think there's some race condition going on. This is super annoying and makes me wondering if going for devcontainers was a good idea at all...
If anyone is still having this problem, a workaround is to write your environment variables to a file and use the runArgs --env-file <path-to-env-file>.
If anyone is still having this problem, a workaround is to write your environment variables to a file and use the runArgs
--env-file <path-to-env-file>.
I have to mount a file from the user's home directory. And of course the repo is used by more than one user... Don't see how using the --env-file argument would be useful here. I need ${localEnv:HOME} or ${localEnv:USER}.