[root@wechat ~]# docker pull mongo:latest
latest: Pulling from library/mongo
7b1a6ab2e44d: Pull complete
90eb44ebc60b: Pull complete
5085b59f2efb: Pull complete
c7499923d022: Pull complete
019496b6c44a: Pull complete
c0df4f407f69: Pull complete
351daa315b6c: Pull complete
5b6df31e95f8: Pull complete
e82745116109: Pull complete
98e820b4cad7: Pull complete
Digest: sha256:cf9f5df5419319390cc3b5d9abfc2d0d0b149b3e04a6c9936990129e3e29b579
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest
[root@wechat ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest 4253856b2570 2 weeks ago 701MB
mcr.microsoft.com/mssql/server 2019-latest 80bdc8efc889 2 months ago 1.55GB
[root@wechat ~]# docker run -itd --name mongo -p 27017:27017 mongo --auth
2a5b08db388782d2008ed6ddf1ff193f5047467f3cb48d60abc26afb9487a23a
[root@wechat ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a5b08db3887 mongo "docker-entrypoint.s…" 12 seconds ago Up 10 seconds 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp mongo
4d0035c29a1f mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 2 weeks ago Up 2 weeks 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp sqlserver
[root@wechat ~]# docker exec -it mongo mongo admin
MongoDB shell version v5.0.4
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0c2d07a5-3cfb-4883-9c1c-2da5b53aba4a") }
MongoDB server version: 5.0.4
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
> db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
"readWriteAnyDatabase"
]
}
> db.auth('admin', '123456')
mongodb docker 部署
最新推荐文章于 2024-06-02 23:52:00 发布