Docker下使用MongoDB

一 下载镜像
[root@localhost mongodb]# docker pull mongo
Using default tag: latest
latest: Pulling from library/mongo
d13d02fa248d: Pull complete
bc8e2652ce92: Pull complete
3cc856886986: Pull complete
c319e9ec4517: Pull complete
b4cbf8808f94: Pull complete
cb98a53e6676: Pull complete
f0485050cd8a: Pull complete
ac36cdc414b3: Pull complete
61814e3c487b: Pull complete
523a9f1da6b9: Pull complete
3b4beaef77a2: Pull complete
Digest: sha256:d13c897516e497e898c229e2467f4953314b63e48d4990d3215d876ef9d1fc7c
Status: Downloaded newer image for mongo:latest
二 使用容器
[root@localhost mongodb]# docker run --name mymogo -d mongo --auth
b0e1869ffd890cb06428c0897d4e5ce892c8e1780fd5f89b9e0b70f6c101876a
[root@localhost mongodb]# docker exec -it mymogo mongo admin
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017/admin
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> db.createUser({ user: 'jsmith', pwd: 'some-initial-password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
"db" : "admin"
        }
    ]
}Successfully added user: {
    "user" : "jsmith",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}
> Successfully added user: {
...     "user" : "jsmith",
...     "roles" : [
...         {
...             "role" : "userAdminAnyDatabase",
...             "db" : "admin"
...         }
...     ]
... }
2017-12-03T00:48:51.770+0000 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:13
三 参考
https://hub.docker.com/_/mongo/

你可能感兴趣的:(Docker)