I'm running the MongoDB/MongoExpress stack via docker compose up
as presented here:
# Use root/example as user/password credentials
version: '3.1'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
Everything works, but from the output of MongoExpress I can read
mongotest-mongo-express-1 | Mongo Express server listening at http://0.0.0.0:8081
mongotest-mongo-express-1 | Server is open to allow connections from anyone (0.0.0.0)
mongotest-mongo-express-1 | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
In fact, by connecting to localhost:8081
I have to provide admin
and pass
as access credentials.
I would like to change this behaviour directly from the Dockerfile by setting the default username and password
Following this documentation, I modified the mongo-express
environment as follows:
environment:
ME_CONFIG_MONGODB_ENABLE_ADMIN: false
ME_CONFIG_MONGODB_AUTH_DATABASE: custom_db_name
ME_CONFIG_MONGODB_AUTH_USERNAME: custom_username
ME_CONFIG_MONGODB_AUTH_PASSWORD: custom_password
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
but nothing has changed, except for Mongo, which has gone from having three databases (admin
, config
and local
) to only one (test
).
Thank you for any help you can give me.
I have the same problem and I found a solution that works for me. I've checked the default config file that is used by mongo-express.
Just set the
ME_CONFIG_BASICAUTH
variable totrue
.The
docker-compose.yml
file may look like the following:I recommend using
ME_CONFIG_MONGODB_URL
, this makes the connection much faster, but it works without this line.Of course, you need to have a
.env
file with the following variables in the same directory asdocker-compose.yml
.Sample
.env
file:Unfortunately, it doesn't fix the problem when you are setting
ME_CONFIG_MONGODB_ENABLE_ADMIN
tofalse
, but I assume you can just use your ownconfig.js
and pass it to docker.