How can I use a single .env file for multiple Docker Compose projects?

0
5
Asked By CuriousCat42 On

I'm trying to manage several Docker Compose projects from a single .env file that contains a directory path, but I'm hitting a roadblock. I've placed this .env file on my NAS share, with a variable set for the directory location as DIR=/path/to/location. I've also included this in my Compose files using the env_file option, but it doesn't seem to work. How can I properly reference this directory using one single .env file? I want to streamline it so I only have to change the directory in one spot instead of adjusting it in each Compose file.

1 Answer

Answered By TechieTurtle77 On

You might want to place your .env file in the project directory where your main Compose file is located. According to the Docker documentation, relative paths for the env_file option are resolved from the parent folder of the Compose file. Just a heads up, using absolute paths can make your Compose files less portable, and Docker may warn you about this.

QuestionAsker99 -

So if I have a masterprojects directory containing multiple project directories, should I place the .env in the masterprojects folder instead of in each individual project folder? I did try that too but still faced issues.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.