侧边栏壁纸
  • 累计撰写 30 篇文章
  • 累计创建 35 个标签
  • 累计收到 4 条评论

docker 部署 mongodb

GoDan
2022-06-22 / 0 评论 / 0 点赞 / 187 阅读 / 2,253 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-06-22,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

搜索可用镜像

https://hub.docker.com/_/mongo?tab=tags&page=1&name=5.0.8

image-1655869168745

下载镜像

# docker pull mongo:5.0.8
5.0.8: Pulling from library/mongo
d5fd17ec1767: Pull complete
a3d1e6b0e1ff: Pull complete
015ccc3eeca8: Pull complete
0129deec1aaf: Pull complete
3b9522656704: Pull complete
42557cfd554b: Pull complete
99e708669a41: Pull complete
398ab1056acc: Pull complete
568df027d825: Pull complete
Digest: sha256:50d8918de7b076feceb9ba1ee264afd5f67fb4baaff07949f3b9de92cdca79c2
Status: Downloaded newer image for mongo:5.0.8
docker.io/library/mongo:5.0.8

# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
mongo        5.0.8     96c85f49715a   4 weeks ago     690MB

运行镜像

# docker run -d --name mongodb -v /data/db/mongodb:/data/db -p 27077:27017 mongo:5.0.8 --auth

参数说明

  • –auth 开启认证

进入容器创建用户

# docker exec -it mongodb mongo admin
MongoDB shell version v5.0.8
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
{"t":{"$date":"2022-06-22T03:39:47.994Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available","message":"Protocol not available","category":"asio.system","value":92}}}
Implicit session: session { "id" : UUID("2e2aa77f-61ac-4daf-b344-90dbb1756a9c") }
MongoDB server version: 5.0.8
================
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
admin
> db.createUser(
...  {
...   user : "admin",
...   pwd : "123456",
...   roles: [ { role : "root", db : "admin" } ]
...  }
... )
0

评论区