Is it possible to configure mongo-express auth to present a login screen and control access to databases?

4.9k Views Asked by At

I'm setting up my first docker containers with mongo and mongo-express using the official docker-compose instructions e.g. something like this:

# 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/

I can access mongo-express through my browser but there is no login screen it just loads all of the tables immediately - no authentication. Is there a way to configure mongo-express authentication to load a login screen to accept env vars in the docker-compose yml file and prevent immediate access to the tables?

2

There are 2 best solutions below

0
On

The mongo docker container provides env vars to control access to admin panel via basic auth only. Other recommendations are to add your own via passport etc, so wouldnt use basic auth in production, but this works fine for testing small dbs.

  • ME_CONFIG_MONGODB_ENABLE_ADMIN
  • ME_CONFIG_BASICAUTH_USERNAME
  • ME_CONFIG_BASICAUTH_PASSWORD
1
On

I find it on this one: https://hub.docker.com/_/mongo-express

It will help you with some config related to the authentication popup