![](/img/trans.png)
[英]How pass environment variables in the container using Dockerfile but with a separate file for environment variables like .env
[英]How can I use an env file to pass environment variables into a standalone vscode remote container?
在項目的.devcontainer
目錄中添加一個聲明環境變量的文件,在本例中.env
:
D:. │ .gitignore │ README.md │ ├───.devcontainer │ .env │ devcontainer.json │ Dockerfile │ └───.vscode settings.json
.env
:
MY_URL=https://my.com/
MY_SECRET=unicorns
然后在您的devcontainer.json
中,您可以定義runArgs
將.env
文件作為env-file
參數傳遞給 Docker CLI run
命令。 這使用了${localWorkspaceFolder}
變量,該變量擴展為本地源代碼的包含目錄:
devcontainer.json
:
{ "name": "Go", "dockerFile": "Dockerfile", "runArgs": [ "--env-file", "${localWorkspaceFolder}/.devcontainer/.env" ], ... }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.