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
Relative path to env_file #4764
Comments
This has been answered previously: See the disambiguation page: https://docs.docker.com/compose/environment-variables/ |
Hey @shin- , i have the exact problem.
Inside ./app/ i have my symfony application with its own .env and i want the env vars used for building the images to be put in the same .env, to make it work i have 2 x .env, one in docker-compose dir and one in my app dir |
Afaik the environment variables are imported in the application but you can't use them in your docker-compose file (like you did with NGINX_PORT. Use a separate .env file for that in the same directory and load that from the application if you really really need it. |
Is there an update regarding that issue? |
Relative paths are accepted in |
So in the yml file So if given the following file locations
Then we'd have foooo:
env_file:
- ./../../envs/my_vars.env How is the behavior when using # relative to cwd
docker-compose -f projX/subdir/docker-compose.yml --env-file ./envs/my_vars.env up or rather # relative to yml
docker-compose -f projX/subdir/docker-compose.yml --env-file ./../../envs/my_vars.env ? |
While this behavior is indeed specified in the docs, it could have been highlighted because it is a common reason for confusion. |
I have a problem with my .env file when it's not in the same folder as the docker-compose file. When I place it in a subfolder and reference it, it will simply say the variables are undefined and will default to a blank string. When I remove the .env file it says it can't find the .env file, so it finds the file but doesn't do anything. When I move the .env file to the same directory as the docker-compose file and update it's path or create a symlink instead, all works fine.
Apparently docker-compose has issues with loading env files that are not in the same directory as the docker-compose file.
Currently I "fixed" this by symlinking the .env file as it's shared with a Laravel project in a subfolder.
My docker-compose file (simplified):
The text was updated successfully, but these errors were encountered: