Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup/Add Mongo/Mongo Express Docker Compose #9

Merged
merged 7 commits into from
Oct 9, 2023
39 changes: 39 additions & 0 deletions mongo-mongo-express/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Mongo-Mongo-Express Docker Compose

It contains docker instances for both **Mongo** & **Mongo Express** internally connected via bridge network.

## Mongo

Mongo, the database server itself can be accessed on host machine (localhost) on port _27017_.

### Description

Below configuration are already set by default via `mongoCreds.env` file and can be modified by overriding the same.

| Config | Value | Comment |
| -------- | ----- | -------------------------------- |
| Port | 27017 | Exposed at localhost (127.0.0.1) |
| Username | root | |
| Password | root | |

An example of connection string to interact with MongoDB is as below.

[mongodb://root:root@localhost:27017](mongodb://root:root@localhost:27017)

## Mongo Express

Mongo Express is integrated to graphically visualize the mongo database.
It can be accessed on host machine (localhost) web browser at [http://localhost:8081](http://localhost:8081).

### Configuration

Below configuration are already set by default via `mongoExpressCreds.env` file and can be modified by overriding the same.

| Config | Value | Comment |
| -------- | ----- | -------------------------------- |
| Port | 8081 | Exposed at localhost (127.0.0.1) |
| Username | root | |
| Password | root | |
| BasicAuth Username | root | This will be used to authenticate the user when they open the express in the browser. |
| BasicAuth Password | root | This will be used to authenticate the user when they open the express in the browser. |

38 changes: 38 additions & 0 deletions mongo-mongo-express/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
services:
mongo:
image: mongo
container_name: mongo
restart: unless-stopped
ports:
- 27017:27017
env_file:
- mongoCreds.env
volumes:
- mongo-data:/data/db
networks:
- mongo-network

mongo-express:
image: mongo-express
container_name: mongo_express
restart: unless-stopped
ports:
- 8081:8081
env_file:
- mongoExpressCreds.env
volumes:
- mongo-express-data:/data/configdb
networks:
- mongo-network

# Bridge type of network connecting to both (mongo, mongo-express) containers.
# As recommended by docker (https://docs.docker.com/network/bridge)
networks:
mongo-network:
name: mongo-network
driver: bridge

# Named volumes for persisting necessary containers' data across restart.
volumes:
mongo-data:
mongo-express-data:
2 changes: 2 additions & 0 deletions mongo-mongo-express/mongoCreds.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=root
5 changes: 5 additions & 0 deletions mongo-mongo-express/mongoExpressCreds.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ME_CONFIG_MONGODB_ADMINUSERNAME=root
ME_CONFIG_MONGODB_ADMINPASSWORD=root
ME_CONFIG_MONGODB_SERVER=mongo
ME_CONFIG_BASICAUTH_USERNAME=root
ME_CONFIG_BASICAUTH_PASSWORD=root