Docker Project: MongoDB with Mongo Express - Avery-Luther/SYS-265 GitHub Wiki
In this project I used Docker to quickly make a Mongo database with a Mongo Express web front-end. MongoDB is an open source, JSON-based database software. This is very useful as it makes it very easy to import data into a script or program. Here were the broad steps to creating the database assuming that you have Docker and Docker Compose installed:
- Create and write a compose.yaml file to install the MongoDB and Mongo Express images, and set their appropriate environment variables.
- Use docker-compose to install and run the images.
- Connect to the server through the web interface.
- Profit.
Step One: Creating compose.yaml
Use Vim to create a file called compose.yaml. In that file, paste the following config into the file:
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: yourusernamehere
MONGO_INITDB_ROOT_PASSWORD: yourpasswordhere
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: yourusernamehere
ME_CONFIG_MONGODB_ADMINPASSWORD: yourpasswordhere
ME_CONFIG_MONGODB_URL: mongodb://yourusernamehere:yourpasswordhere@mongo:27017/
ME_CONFIG_BASICAUTH_USERNAME: yourusernamehere
ME_CONFIG_BASICAUTH_PASSWORD: yourpasswordhere
Now that you have the config, change yourusernamehere and yourpasswordhere to your desired credentials. You can also change the ports to something other than the default as well. Close out of Vim with a :wq and you are all set!
Step Two: docker-compose
In the same directory as compose.yaml, run docker-compose up -d
to start the images in the background. Once the command resolves, execute docker ps
and make sure that you can see mongo and mongo express running on your desired ports. If you can, you're all set and can move on to step three!
Step Three: Connecting to The Server.
Open a web browser on another machine, and go to http://ServerIpOrDomainName:YourPort. If you get a password prompt, use the ME_CONFIG_BASICAUTH
credentials from your compose.yaml file. If all goes well you should now have access to Mongo Express!
Step Four: Profit
With Mongo, you can create modify and delete databases. What you do with these databases is up to you! Have fun.
Sources:
- https://hub.docker.com/_/mongo/ MongoDB docker hub page
- https://hub.docker.com/_/mongo-express/ Mongo Express docker hub page
- https://github.com/mongo-express/mongo-express-docker Mongo Express Github