This folder contains instructions to set up a MongoDB environment with a web interface provided by Mongo-Express.
-
Navigate to this folder
Open your terminal and go to the folder containing thedocker-compose.ymlfile. -
Run the command:
docker compose up -d
Explanation: This command will download the MongoDB and Mongo-Express images, start the containers, and configure the environment.
- Host:
mongodb://localhost:27017 - Credentials:
- User:
admin - Password:
admin123
- User:
You can connect using any MongoDB client, such as MongoDB Compass or the command line mongosh:
mongosh mongodb://admin:admin123@localhost:27017
Tip
For IDE integration:
- IntelliJ: use Database Navigator plugin.
- Visual Studio Code: install MongoDB for VS Code.
- URL:
http://localhost:8081 - Credentials:
- User:
admin - Password:
pass
- User:
The web interface allows you to easily explore and manage your MongoDB databases.
services:
mongodb:
image: mongo:latest
container_name: mongodb_container
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin123
volumes:
- mongodb_data:/data/db
mongo-express:
image: mongo-express:latest
container_name: mongo_express
depends_on:
- mongodb
ports:
- "8081:8081"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: admin123
ME_CONFIG_MONGODB_SERVER: mongodb
volumes:
mongodb_data:-
MongoDB:
-
image: mongo:latest: Uses the latest official MongoDB image. -
container_name: mongodb_container: Names the MongoDB container. -
ports: Maps container port27017to the host machine. -
environment: Sets the administrator credentials:MONGO_INITDB_ROOT_USERNAME: Admin userMONGO_INITDB_ROOT_PASSWORD: Admin password
-
volumes: Uses a persistent volume (mongodb_data) to store database data.
-
-
Mongo-Express:
-
image: mongo-express:latest: Uses the latest official Mongo-Express image. -
container_name: mongo_express: Names the Mongo-Express container. -
depends_on: Ensures MongoDB starts before Mongo-Express. -
ports: Maps container port8081to host port8081for web access. -
environment: Configures admin credentials and MongoDB server:ME_CONFIG_MONGODB_ADMINUSERNAME: Admin user for Mongo-ExpressME_CONFIG_MONGODB_ADMINPASSWORD: Admin password for Mongo-ExpressME_CONFIG_MONGODB_SERVER: Service name of the MongoDB container
-
-
Volumes:
mongodb_data: Persistent volume for MongoDB database data.
Important
- Make sure ports
27017and8081are free on your machine before starting the containers. - Mongo-Express depends on MongoDB being up and running, so don’t stop MongoDB while using the web interface.