Search code examples
dockervisual-studio-codedocker-composevscode-remotevscode-devcontainer

vscode dev container environment variables not exposing to docker-compose


My docker-compose.yml looks like this

version: "3.8"
services: 
  vscode:
    volumes:
      - ..:/workspace:cached
      - $SSH_AUTH_SOCK:/ssh-agent
      - /var/run/docker.sock:/var/run/docker.sock
    environment: 
      - SSH_AUTH_SOCK=/ssh-agent

Problem is that vscode does not want to give any kind of possibility to do an equivalent of docker-compose run --env ... thus I'm left with

WARNING: The SSH_AUTH_SOCK variable is not set. Defaulting to a blank string.

Is there any way for me to expose my variables from my host to the dev container without using an .env file or anything like that?


Solution

  • I have opened an issue on github yesterday. The outcome is that if you use WSL, then you need to export this variable through your ~/.profile or ~/.bash_profile.

    We are using a non-interactive login shell to probe the environment variables in WSL and use these as the "local" variables.

    https://github.com/microsoft/vscode-remote-release/issues/5806