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
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.
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.