Check available MongoDB versions
docker search mongo
2. Obtain the MongoDB image of the latest version
docker pull mongo:latest
Copy the code
3. View the local mirror
docker images
Copy the code
4. Run the container
docker run -itd --name mongo -p 27017:27017 mongo --auth
Copy the code
Check the container
docker ps
Copy the code
6. Enter the container
docker exec -it mongo mongo admin
Copy the code
Create an account
db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
Copy the code
Eight, test,
db.auth('admin', '123456')
Copy the code