下载镜像
docker pull mongo
下载如下
Using default tag: latest
Trying to pull repository docker.io/library/mongo ...
latest: Pulling from docker.io/library/mongo
9ff7e2e5f967: Pull complete
59856638ac9f: Pull complete
6f317d6d954b: Pull complete
a9dde5e2a643: Pull complete
815c6aedc001: Pull complete
8566b2594855: Pull complete
01c9fe451980: Pull complete
5c9e7bc12cea: Pull complete
c64dd2c4159a: Pull complete
c283cca25ace: Pull complete
051b3304da4a: Pull complete
ab4327c34933: Pull complete
80003bc32b79: Pull complete
Digest: sha256:05f12b17aa35948848c0d3f0198ce10c7f3e37438724911d0d8f9b6643535599
Status: Downloaded newer image for docker.io/mongo:latest
查看mongo镜像
docker images mongo
运行安装命令:
docker run --name mongodb -p 27017:27017 -d mongo --auth
为MongoDB添加管理员用户
进入MongoDB
docker exec -it f61df2709f78 mongo admin
f61df2709f78是你的MongoDB容器的id
创建一个 admin 管理员账号:
db.createUser({
user: 'root', pwd: 'root', roles: [ {
role: "userAdminAnyDatabase", db: "admin" } ] });
退出
exit
操作如下