How to Use a Single .env File for Multiple Docker Compose Projects?

0
0
Asked By CuriousCoder92 On

I'm trying to streamline my Docker Compose projects by using a single .env file to define the directory location for bind mounts. I have a .env file stored on my NAS share with a variable like DIR=/path/to/location where I keep the configurations for multiple projects. I've set it up using the env_file option in my Compose files, but it's not working as expected. How can I configure my Docker Compose files to properly utilize this single .env file for the directory location? I want to be able to change the location from just one file instead of updating it in multiple places.

1 Answer

Answered By TechieJoe57 On

You might need to make sure the .env file is placed correctly within your project directory structure. According to the documentation, it's best to place the .env file inside the root folder of your project. This way, the relative paths can resolve correctly from the Compose file's location. Also, keep in mind that using absolute paths can trigger warnings about portability.

ProjectNinja22 -

So, should I create a single .env file in my main project folder, or do I need to have one in each individual project directory? I've tried placing one in a folder labeled masterprojects, but it didn't work either. I still used ..../.env in my Compose file.

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.