4

To build my remote environment I need several environmental variables to be set (they are used in the docker-compose file). These are set in my ZSH environment, so running docker-compose build works as expected from the terminal. However these variables are not available when running the reopen in container command. How/where can I set the variables that will be available to vscode when running docker-compose build? Note that I am running vscode-remote-containers from within vscode-remote-WSL.

Thijs D
  • 762
  • 5
  • 20

2 Answers2

3

From the vscode logs it is apparent it calls wsl -d Ubuntu -e /bin/sh ..... docker-compose up to build the container, thus not taking into account any environmental variables set in .bashrc or otherwise. I solved it by putting required variables in the WSLENV like so: WSLENV=REQUIRED_VAR/u:ANOTHER_REQUIRED_VAR/u Then they are available for docker-compose when run from wsl.

Thijs D
  • 762
  • 5
  • 20
1

Have you tried devcontainer.json:

"containerEnv": {
    "MY_CONTAINER_VAR": "some-value-here",
    "MY_CONTAINER_VAR2": "${localEnv:SOME_LOCAL_VAR}"
},
"remoteEnv": {
    "PATH": "${containerEnv:PATH}:/some/other/path",
    "MY_REMOTE_VARIABLE": "some-other-value-here",
    "MY_REMOTE_VARIABLE2": "${localEnv:SOME_LOCAL_VAR}"
}

https://code.visualstudio.com/docs/remote/containers-advanced

johnymachine
  • 781
  • 2
  • 7
  • 28
  • 1
    This concerns setting variables inside the container after it has been built, not during the build step. – Thijs D May 25 '20 at 12:06