Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which to use: containerEnv or remoteEnv? #233

Closed
jcbhmr opened this issue May 1, 2023 · 4 comments
Closed

Which to use: containerEnv or remoteEnv? #233

jcbhmr opened this issue May 1, 2023 · 4 comments

Comments

@jcbhmr
Copy link

jcbhmr commented May 1, 2023

馃憢 hello! this is more a question than an "issue" per-se

if i want to, say, set a laravel env var DB_CONNECTION=sqlite, which should i use?

image

https://containers.dev/implementors/json_reference/

specifically, what's the difference between "supporting service / tool (or sub-processes like terminals) but not the container as a whole" and "overrides environment variables for the container" ??

@jkeech
Copy link
Contributor

jkeech commented May 1, 2023

containerEnv will set the variable on the docker container itself, so all processes spawned in the container will have access to it. But the env var also will be static for the life of the container -- you'd have to rebuild the container to update the value. remoteEnv is applied only to the VS Code server process that is running in the container (or the equivalent for other clients that connect to the container). If you have a background daemon that starts up in the container, it wouldn't see the env var. One benefit of remoteEnv is that you can update the values without having to rebuild the full container though since it would only require the VS Code server process to be relaunched with the updated environment variable value.

In short, I would recommend using containerEnv as much as possible since it allows all processes to see the env var and isn't client-specific. This is true particularly if the value is static. But if the value is not static, putting it in remoteEnv might be better.

@jcbhmr
Copy link
Author

jcbhmr commented May 1, 2023

Thanks for your overview of the differences! 鉂わ笍 You perfectly answered my question. I'll use containerEnv for my DB_CONNECTION=sqlite variable.

馃 Would it be possible to put something like this into the https://containers.dev/ website docs? Does an explanation already exist that I just missed/misunderstood?

@jcbhmr jcbhmr closed this as completed May 1, 2023
@jkeech
Copy link
Contributor

jkeech commented May 1, 2023

馃 Would it be possible to put something like this into the https://containers.dev/ website docs? Does an explanation already exist that I just missed/misunderstood?

Good idea! @bamurtaugh can we expand the docs to describe the differences a bit better and encourage containerEnv over remoteEnv in many cases (including by moving containerEnv higher in the list above remoteEnv).

@bamurtaugh
Copy link
Member

Thanks for opening @jcbhmr, and thanks for tagging me @jkeech! This sounds like a great idea to me too.

I opened an issue and can add this to my backlog: devcontainers/devcontainers.github.io#203. @jcbhmr if you'd like to open a PR, that'd be fantastic too as we welcome any and all contributions, and I'd be happy to review too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants