Introduction: Docker is a qualified Java development engineer must master the knowledge, fox will write down their own understanding, this article only represents my summary and understanding, if there are mistakes, welcome to correct…

1. Download the Mongo image

Docker pull mongo: 4.2

2. Start the first time

Docker run -p 27017:27017 –name mongo -v /home/docker_data/mongo/db:/data/db –privileged=true -d mongo:4.2

3. Enter the Docker container

1) Docker exec -it mongo bash 2) mongo 3) use admin; 3) db.createuser ({user: "root", PWD: "aghuiGo520", roles: [{role: "userAdminAnyDatabase", db: "admin"}]}) exit exitCopy the code

Exit mongo twice with the container

docker stop mongo

docker rm mongo

4. Create the root account and save the information in the docker_data folder. The next time the container is created, there will be permission validation.

1) docker run -p 27017:27017 --name mongo --restart=always -v /home/docker_data/mongo/db:/data/db --privileged=true -d Mongo :4.2 --auth 2) Docker exec -it mongo bash 3) mongo -u "root" -p "aghuiGo520" --authenticationDatabase "admin" 5) db.createuser ({user: "aghuiGo", PWD: "aghuiGo520", roles: [{role: "dbOwner", db: "suning-sports" }] })Copy the code

Then exit, and Mongo is deployed

database: suning-sports

username: aghuiGo

password: aghuiGo520


Create the second mongodb user step

Mongo -u "root" -p "aghuiGo520" --authenticationDatabase "admin" enter the root account 3, db. CreateUser ({user: "aghuiGo", PWD: "aghuiGo520", roles: [{role: "dbOwner", db: 3, db.createuser ({user: "aghuiGo", PWD: "aghuiGo520", roles: [{role: "dbOwner", db: "jinrong"}]}) Create the user for the second timeCopy the code

Conclusion: Ever is to learn to read people’s blog technology, some of them have essence blog also have to play around the CV of solution, so the decided to study the knowledge sharing for everyone, mainly want to go to the sea after less detours, more positive energy blog, if there are any errors, welcome to point out mistakes, only hope that we can learn knowledge in my blog, Solve the problem, then it is enough. Thank you! (Please note the original source for reprint)