vscode dev container environment variables not exposing to docker-compose vscode dev container environment variables not exposing to docker-compose docker docker

vscode dev container environment variables not exposing to docker-compose


To expose environment variables from the host through a container, as per the documentation

You can pass environment variables from your shell straight through to a service’s containers with the ‘environment’ key by not giving them a value, just like with docker run -e VARIABLE ...:

web: environment:   - DEBUG

The value of the DEBUG variable in the container is taken from the value for the same variable in the shell in which Compose is run.

Regarding specifically SSH_AUTH_SOCK you should have a look at SSH Agent forwarding inside docker compose container.

Example

Right, problem is that environment variables are not being exposed properly even with doing that.

A simple service using a variable DEBUG.

services:  test:    image: busybox    command: ["echo", "${DEBUG}"]    environment:      - DEBUG

Using it without exporting the variable, it does not work a warning is displayed in the output.

# running the servicedocker-compose up# WARNING: The DEBUG variable is not set. Defaulting to a blank string.# Starting d-compose-env_test_1 ... done# Attaching to d-compose-env_test_1# test_1  | # d-compose-env_test_1 exited with code 0

Now exporting the variable on the host before running it, and it works, the value of the variable is printed.

# exporting the variableexport DEBUG=test# running the servicedocker-compose up# Recreating d-compose-env_test_1 ... done# Attaching to d-compose-env_test_1# test_1  | test# d-compose-env_test_1 exited with code 0