Skip to content

How to allow user-specific environment variables in a container? #255

Answered by Roemer
Roemer asked this question in Q&A
Discussion options

You must be logged in to vote

I got a fairly simple solution for this problem:

  • I have an initializeCommand which makes sure that the file .devcontainer/.env.run exists via touch .devcontainer/.env.run
  • In the runArgs, I have --env-file, ${localWorkspaceFolder}/.devcontainer/.env.run
  • .devcontainer/.env.run is in .gitignore

This allows the file to be empty but whoever needs environment variables added, can add them there.

As a bonus, I also added the possibility to define a .env.build file which is used during the build phase.
When using this, I switched building the container from the dockerfile to the initializeCommand (see microsoft/vscode-remote-release#3545 (comment) for details).

Then I can read the arguments fro…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Roemer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants