7

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?

Tero
  • 140
  • 4
  • 11

2 Answers2

2

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

The Fool
  • 16,715
  • 5
  • 52
  • 86
-2

I just had a similar issue so this may help.

I would run the following:

export VARIABLE=VALUE
sudo docker-compose up

The problem was that I was exporting the environment variable as my user and then running docker-compose as sudo so it wouldn't have the same environment variables.

This can be solved by either adding yourself to the docker group so you can run without sudo

or exporting the variable as root(not recommended)

  • This question is specific to VS code dev containers. Not specific to docker-compose. It seems like eventually this was fixed, see: The fool's answer – Tero Mar 05 '22 at 03:14