How to Create mongodb & web-based interface container on Docker

How to Create mongodb & web-based interface container on Docker

Hello Geeky, so today we are focusing on How to Create mongodb & web-based interface container on Docker. So please read this tutorial carefully so you may comprehend it in a better helpful way.

Guide: How to Create mongodb & web-based interface container on Docker

MongoDB doesn’t need an introduction, the one who is system administrating and developing would already know about it. It is a NoSQL database available to install on popular operating systems to provide a database without a fixed structure, hence easily scalable. Here in this article, we will learn the steps to easily install or create a MongoDB Database server container on the Docker Engine platform.

What do we need to perform in this tutorial?

  • A system with Docker
  • Access to its command line
  • Internet connection

Steps to install MongoDB & Mongo Express on Docker

Make sure you have Docker

The first thing I am assuming is that you already have Docker installed on your system.

Download or Pull MongoDB Docker Image

The best thing that made Docker popular is its repository that holds hundreds of pre-built Images from official and non-official sources. We can use them to create containers instantly, yes, of course, MongoDB is also there. Hence, just on your machine run the Docker Pull command:

docker pull mongo

The above command will pull the latest version image on MongoDB Server on your Docker, however, for any other versions, you have to use the tag. For Example, docker pull mongo:4.4.9. For all available tags, you can see its Github page.

To check the downloaded image on the system, you can use:

docker images

Create MongoDB Database Server Container

We have already the image, now use it to create as many Database running containers as you want. However, before that let’s create a folder on our system to hold the databases data created on the MongoDB running container. As we know once we start using the Database server for commercial usage its data become valuable, but in case we need to delete the container in the future that process will also remove all of its data. Hence, to play safe let’s create a folder-

sudo mkdir /var/dbdata

Now, create Mongo Container:

docker run -it -d -v /var/dbdata:/data/db -p 27017:27017 –name mongodb mongo

Explanation of the above command:

/var/dbdata:/data/db – Assigning our created folder to use for storing MongoDB data.

-p 27017:27017 : Opening Database server container port to access from the host system.

–name MongoDB : Giving some name to our container

mongo : It is the name of the downloaded Image file

Start container:

docker start mongodb

Access MongoDB Database Docker Terminal (Bash Shell)

Now, if you want to access the command line of the Mongo server to create databases and manage them, here is the command:

sudo docker exec -it mongodb bash

Access mongodb docker container command line

Create Mongo Express Web Interface container (optional)

Well, those who want a web-based graphical user interface to manage their Docker MongoDB server databases, can go for the further installation of Mongo Express by creating a container.

docker run –link mongo_db_name_container:mongo -p 8081:8081 -e ME_CONFIG_MONGODB_URL=”mongodb://mongo:27017″ mongo-express

Link your Docker running MongoDB server with Express, by replacing the above “mongo_db_name_container” in the above command.

For example, here we have created a database container with the name- mongodb hence the above command will be:

docker run –link mongodb:mongo -p 8081:8081 -e ME_CONFIG_MONGODB_URL=”mongodb://mongo:27017″ mongo-express

To access the web interface, open your browser and type: http://localhost:8081

Faq

Guide about How to Create mongodb & web-based interface container on Docker


In this guide, we told you about the How to Create mongodb & web-based interface container on Docker; please read all steps above so that you understand How to Create mongodb & web-based interface container on Docker in case if you need any assistance from us, then contact us.

How this tutorial or guide assisting you?


So in this guide, we discuss the How to Create mongodb & web-based interface container on Docker, which undoubtedly benefits you.




Final note

I hope you like the guide How to Create mongodb & web-based interface container on Docker. In case if you have any queries regards this article/tutorial you may ask us. Also, please share your love by sharing this article with your friends and family.

Trickbugs: Get the latest Trick and Tips
Logo
Enable registration in settings - general