In this lesson, I will show how to install MongoDB using Docker compose with the root user and password. To follow this tutorial docker and docker-compose has to be installed on your computer.
version: "2.0"
services:
mongodb_container:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- 27017:27017
volumes:
- mongodb_data_container:/data/db
volumes:
mongodb_data_container:
Here username is root and password is also password. Change the username and password if you want.
Run the following command to download and run the docker container of MongoDB:
docker-compose up -d
Check the container:
docker ps
Check Volumes:
docker volume ls
To run the following command mongo client has to be installed on your computer.
mongo -u root -p password
Another way:
mongo mongodb://root:password@127.0.0.1:27017
Change username, password, and IP address following your installation and server.