MongoDB is available in community package NoSQL database management program and document-oriended database that used for high volume data storage and alternative to traditional relation databases instead of using tables and rows. this is really use for large set of databases also makes use of collections and documents. The collections contain set of document and function which is similar to Relational Database Management Systems.
Here, we will install a MongoDB in Docker container using the Docker-Compose file.
Make sure that have you installed a docker-compose package in your system or instance and save the below code in a file "docker-compose.yaml" or "docker-compose.yml"
version: "3.8"
services:
mongodb:
image : mongo
container_name: mongodb-dev
environment:
- MONGO_INITDB_ROOT_USERNAME=username
- MONGO_INITDB_ROOT_PASSWORD=password
- PUID=1000
- PGID=1000
volumes:
- /opt/mongodb/database:/data/db
command: [--auth]
ports:
- 27017:27017
restart: always
networks:
default:
external: true
name: mongodb_default
Next, save a file and run the command,
$ sudo docker-compose up -d
The docker can pull the latest docker image from the registry and run a container in 27017 port, username and password configured by default.
Check the docker container using the command below,
$ docker container ls | grep mongodb-dev
Install a MongoDB Compass software in your local machine and test the database connectivity with above hostname, port number, username and password. The format is,
Comments (0)