Diary

# Setting up MongoDB and Mongo Express with Docker (docker-compose)

1 Mins read

Access from browser:

http://localhost:8081

ME_CONFIG_MONGODB_ADMINUSERNAME: root 
ME_CONFIG_MONGODB_ADMINPASSWORD: password

Tried logging in with the specified ID and password in the browser but couldn’t log in? Hmm…

Turned out Basic authentication environment variables for the browser were needed.

ME_CONFIG_BASICAUTH_USERNAME: admin
ME_CONFIG_BASICAUTH_PASSWORD: password

Create a “docker-compose.yml” file (code below)

Run “docker-compose up -d” command in the terminal


version: '3.1'

services:

  mongo:
    container_name: mongo-dev
    image: mongo
    restart: always
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
    volumes:
      - ./configdb:/data/configdb
      - mongoDataStore:/data/db

  mongo-express:
    container_name: mongo-express
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_URL: mongodb://root:password@mongo:27017/
      ME_CONFIG_BASICAUTH_USERNAME: admin
      ME_CONFIG_BASICAUTH_PASSWORD: password

volumes:
  mongoDataStore:
    driver: local

Also verify connection from Mac terminal (make sure testDB and such are created beforehand via express, etc.)

mongosh "mongodb://root:password@localhost:27017/testDB?authSource=admin"

Current Mongosh Log ID: 65be609e7384r68762b10b0