mongdb installation

docker installation

Install

pull image

docker pull mongo:4.4.14-focal


create container

docker run -itd --name mongo -p 8036:27017  mongo:4.4.14-focal --auth

configuration manager

into the container

docker exec -it mongo bash


enter terminal

mongo


Enter the admin database

use admin


Create an administrator account

db.createUser({ user: "root", pwd: "xx", roles: [{ role: "root", db: "admin" }] })


Verify that the user is added successfully

db.auth("root", "xx");


If it returns 1, it means success

enter terminal

into the container

docker exec -it mongo bash


enter terminal

mongo


log in as administrator

use admin
switched to db admin
db.auth("root","xx")

Guess you like

Origin blog.csdn.net/m0_63040701/article/details/131688290