Vscode-remote-release: .env file in project root is not used

Created on 8 Jun 2020  路  4Comments  路  Source: microsoft/vscode-remote-release


  • VSCode Version: 1.45.1
  • Local OS Version:macOS Catalina 10.15.5
  • Remote Extension/Connection Type: Docker

Steps to Reproduce:

  1. Create any simple repo based on an existing dockerfile
  2. Create a .env file in the root of the project with something like FOO=bar
  3. build and run the container

According to the documentation: "VS Code will automatically pick up a file called .env in your workspace root". However, the environment variable is not present in the terminal when running env.

containers doc

Most helpful comment

The documentation needs a small update: .env is only picked up automatically by docker-compose. docker and docker-compose both support explicitly specifying an env-file as described in the documentation.

All 4 comments

Note that if you explicity load the .env file using "runArgs": ["--env-file","${localWorkspaceFolder}/.env"], then the env variable is present

Present as well here:

VSCode Version: 1.46.0
Local OS Version: archlinux 5.6.15-arch1-1
Remote Extension/Connection Type: Docker

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

Edit devcontainer.json and add a path to the .env file relative to the location of devcontainer.json

However, the env file is also not detected relative to the devcontainer.json path. The fix including ${localWorkspaceFolder}/path/to/env does resolve the issue. Regression or should docs be updated?

The documentation needs a small update: .env is only picked up automatically by docker-compose. docker and docker-compose both support explicitly specifying an env-file as described in the documentation.

Good to know I wasn't crazy! And I have gotten the .env file to work with a docker-compose.yml file, so I can confirm it does work in that case. Unfortunately, I was trying to make my project setup work for the 'open from repository' feature, which doesn't work with docker-compose-based .devcontainer configurations.

Was this page helpful?
0 / 5 - 0 ratings