MongoExpress not reading login/password from .env file

318 Views Asked by At

I am using docker-compose where I set the environmental variables to be:

environment:

- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}

only when I do:

environment:
- ME_CONFIG_BASICAUTH_USERNAME="username"
- ME_CONFIG_BASICAUTH_PASSWORD="password"

it works there, but I want to make it so you can edit the credentials easily.

for some reason when i do the environmental variables for mongoDB it works:

environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}

here is my env file

MONGO_ROOT_USER=admin
MONGO_ROOT_PASSWORD=admin
MONGOEXPRESS_LOGIN=punkmeister
MONGOEXPRESS_PASSWORD=testingStuff
1

There are 1 best solutions below

1
On

I think you should try

environment:
- MONGO_INITDB_ROOT_USERNAME
- MONGO_INITDB_ROOT_PASSWORD

and your .env file

MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=adminpassword