【问题标题】:How to set the environmental variables when starting vscode-remote-containers from within vscode-remote-WSL?从 vscode-remote-WSL 中启动 vscode-remote-containers 时如何设置环境变量?
【发布时间】:2020-05-10 19:22:09
【问题描述】:

要构建我的远程环境,我需要设置几个环境变量(它们在 docker-compose 文件中使用)。这些是在我的 ZSH 环境中设置的,因此从终端运行 docker-compose build 可以正常工作。但是,这些变量在运行 reopen in container 命令时不可用。在运行 docker-compose build 时,如何/在哪里设置可用于 vscode 的变量?请注意,我在 vscode-remote-WSL 中运行 vscode-remote-containers。

【问题讨论】:

    标签: vscode-remote


    【解决方案1】:

    从 vscode 日志中可以看出,它调用 wsl -d Ubuntu -e /bin/sh ..... docker-compose up 来构建容器,因此不考虑在 .bashrc 或其他地方设置的任何环境变量。我通过将所需的变量放入 WSLENV 来解决它,如下所示:WSLENV=REQUIRED_VAR/u:ANOTHER_REQUIRED_VAR/u 然后,当从 wsl 运行时,它们可用于 docker-compose。

    【讨论】:

      【解决方案2】:

      你试过devcontainer.json

      "containerEnv": {
          "MY_CONTAINER_VAR": "some-value-here",
          "MY_CONTAINER_VAR2": "${localEnv:SOME_LOCAL_VAR}"
      },
      "remoteEnv": {
          "PATH": "${containerEnv:PATH}:/some/other/path",
          "MY_REMOTE_VARIABLE": "some-other-value-here",
          "MY_REMOTE_VARIABLE2": "${localEnv:SOME_LOCAL_VAR}"
      }
      

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

      【讨论】:

      • 这涉及在容器构建后在容器内设置变量,而不是在构建步骤期间。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多