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?
The first thing I am assuming is that you already have Docker installed on your system. If not then as per your operating system go through the below-given tutorials and set up the one for you.
• How to install and setup Docker Container on AlmaLinux 8
• Install and setup Docker Container on Rocky Linux 8 or CentOS/RHEL 8
• Install Docker CE on Debian 11 Bullseye Linux
• Best way to install Docker on Ubuntu 20.04…
• How to install Docker on Windows 10
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:
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:
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-
Now, create Mongo Container:
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
Now, if you want to access the command line of the Mongo server to create databases and manage them, here is the command:
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.
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:
To access the web interface, open your browser and type:
document.getElementById( “ak_js_1” ).setAttribute( “value”, ( new Date() ).getTime() );
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Linux Shout crafted as a part of our main portal H2S Media to publish Linux related tutorials and open source Software.