We've been using direnv for quite some time now to automatically load environment variables in a specific folder. And since version 3, docker-compose seems to support .env files.
The .envrc
files used by direnv use export
:
export NODE_ENV=development
Using the same file with docker-compose doesn't seem to work, only without export
I get the value for the variable.
NODE_ENV=development
Any ideas on how to unify this into a single .env
or .envrc
file or an alternative to direnv?
Here is an alternative solution based on the comment chain for this answer
direnv ships with a stdlib that can be used to support classical 'dotenv' settings
# myproject/.envrc - name of current file
# Usage:
# dotenv <optionalPathToDotEnvFile> or defaults to .env
dotenv
# myproject/.env
FOO=BAR
this is especially helpful when using container systems like docker that support the dotenv style