python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

.env not found in docker

Open Brice-D opened this issue 3 years ago • 2 comments

Hello,

project structure:

root_directory | --recommencer |-- src |-- services init.py extract.py (which is calling config = dotenv_values('../.env') -> it works locally) init.py app.py .env (is in the root_directory)

While building my docker image and start my container (I've the same structure in my docker image/container as locally), extract.py can't find .env anymore, I have to call it like this config = dotenv_values('.env'). This make local testing difficult as I've to change how I call config = dotenv_values() while peforming my local test and change it to build my image.

Any idea how I can solve this without changing my project structure? image

Brice-D avatar Jul 02 '23 18:07 Brice-D

I recently started seeing the same problem. I've given up on debugging it and decided to manually fix it by doing something like:

config = dotenv_values('.env')
if os.environ.get("IMPORTANT_ENV") == None:
    os.environ["IMPORTANT_ENV"] = config.get("IMPORTANT_ENV")

fozziethebeat avatar Jul 05 '23 00:07 fozziethebeat

I did the same,

flask_debug = os.environ.get('FLASK_DEBUG')
config = any

if flask_debug is not None:
    config = dotenv_values('.env')
else:
    config = dotenv_values('../.env') # for local testing

Brice-D avatar Jul 05 '23 07:07 Brice-D