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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Loading Environment Variables in Docker Container #244

Closed
mehrabmp opened this issue Jun 2, 2024 · 5 comments
Closed

Issue with Loading Environment Variables in Docker Container #244

mehrabmp opened this issue Jun 2, 2024 · 5 comments

Comments

@mehrabmp
Copy link

mehrabmp commented Jun 2, 2024

When I run my app using Docker, I get errors like "Invalid environment" for all my environment variables in the browser console. However, I'm certain that my environment variables are loaded into the container, as I have verified using the docker exec bash command.
The issue I noticed is that when I build my image with the .env file included, everything works fine. However, when I add .env to .dockerignore, I encounter this problem. It seems that the library only works with .env files and cannot get environment variables from the system or the Docker container.

@michielswaanen
Copy link

Experiencing the same issue after upgrading to Docker 4.30.0. I'm not sure if it's related to the upgrade.

@robodove
Copy link

Are you using turborepo to build/run ?

https://turbo.build/repo/docs/reference/run#--env-mode-option

Turbo --env-mode is strict by default (only env variables specified in the config are passed to the container)

Using

$ turbo run build --env-mode loose

fixes this

@mehrabmp
Copy link
Author

Are you using turborepo to build/run ?

https://turbo.build/repo/docs/reference/run#--env-mode-option

Turbo --env-mode is strict by default (only env variables specified in the config are passed to the container)

Using

$ turbo run build --env-mode loose

fixes this

No I'm using create-t3-app

@robodove
Copy link

Are you using turborepo to build/run ?
https://turbo.build/repo/docs/reference/run#--env-mode-option
Turbo --env-mode is strict by default (only env variables specified in the config are passed to the container)
Using

$ turbo run build --env-mode loose

fixes this

No I'm using create-t3-app

that has nothing to do with deployment ?

Check your Dockerfile / Docker commands if it contains "turbo"..

@juliusmarminge
Copy link
Member

juliusmarminge commented Jul 22, 2024

I don't think this is related to this library.

You need to:

  • for client side variables, the values have to be known at build-time as these are (most likely) statically replaced by your framework. So your Dockerfile must provide these (either from an env file or build args)
  • for server variables, you don't want to inject these when you build the image. you instead want to provide these when starting the container. To make the build not fail when the variables aren't there, you can set the skipValidation option to something that identifies your build pipeline.

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

4 participants