avatar

JiangBao

This guy is lazy and leaves nothing behind

docker安装mongodb

Published:
|
docker-mongodb

命令行中使用docker pull 拉取目标镜像

 docker pull mongodb/mongodb-community-server:latest 

安装成功后

命令行中使用docker images 查看已经安装成功的镜像,这个时候你的镜像列表里会多出mongodb的镜像

 docker images 

同时如果你安装有docker desktop去查看,也会看到最新安装的镜像

运行mongodb同时配置映射端口

 docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:latest 

docker里的mongodb就会运行起来,同时映射本机端口27017

这里我安装的是社区版本,连接不需要用户密码,在代码里连接mongodb如下格式

 mongodb://localhost:27017/database