Search code examples
vscode-remote

How to set the environmental variables when starting vscode-remote-containers from within vscode-remote-WSL?


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.


Solution

  • 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.