How to Run Mongodb as a Docker Container
Mongodb Is Among the Most Popular Nosql Databases Today. and Containers Offer Easy App Usage and Scalability. in This Article, I’ll Show You How to: Configure...
MongoDB is among the most popular NoSQL databases today. And containers offer easy app usage and scalability. In this article, I’ll show you how to:
- Configure MongoDB as a container in Docker
- Set up the Docker platform with docker-compose
- Create a docker-compose file to create the MongoDB container
- And more
The last part of this tutorial will look at advanced configurations. These can give you a glimpse of the extensibility of a containerized project. So, we’ll create a self-containing project with a MongoDB instance and Mongo Express web interface on a dedicated network and docker volume to maximize the portability of the project.
Let’s get started.
(This article is part of our MongoDB Guide. Use the right-hand menu to navigate.)
Docker containers & MongoDB
Docker is a tool to create, deploy, and run applications using containers easily. A container is a standard unit of software that can be used to package applications and all the dependencies to a single package. These containers can be run on any server platform regardless of the underlying configuration or hardware structure.
Docker can be used to run MongoDB instances. Setting up MongoDB as a container allows the user to create a portable and extensible NoSQL database. A containerized MongoDB instance behaves exactly like a non-containerized MongoDB instance without having to worry about the underlying configuration.
Interested in Enterprise DevOps? Learn more about DevOps Solutions and Tools with BMC. ›
Must Read
Installing Docker
In this section, we’ll set up a simple Docker installation to run containers on a Ubuntu-based server. We can get the Docker installation packages from the official Docker repository. Here are the installation steps:
- Update existing packages.
sudo apt update && sudo apt upgrade -y
- Install prerequisite packages.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
- Add the GPG key from the official Docker repository.
curl -fsSL | sudo apt-key add -
- Add the official docker repository to APT sources.
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
- Update the Ubuntu package list.
sudo apt update
- Verify the docker repository.
apt-cache policy docker-ce
- Install the Docker community edition.
sudo apt install docker-ce
- Check the status of the installation with the following command. If the service status returns active (running), Docker is successfully installed and active on the system.
sudo systemctl status docker