下载
使用命令下载docker的镜像.
# 下载 mongoDB4镜像
docker pull mongo:4
# 查看下载好的镜像
docker images
# 输出如下
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo 4 aa22d67221a0 2 weeks ago 493MB
hyperf/hyperf latest a8fdc61b1fc5 3 weeks ago 80.2MB
sc-qvbilam-easyswoole-ide 0.1 87a58e60f7ff 5 months ago 1.12GB
qvbilam/sc-qvbilam-easyswoole-ide 1.0 87a58e60f7ff 5 months ago 1.12GB
centos 7 5e35e350aded 9 months ago 203MB
启动
# 设置容器名称为mymongo 并挂载到指定目录, 后台启动 mongo:4
docker run --name mymongo -v ~/Study/database/MongoDB/data:/data/db -p 27017:27017 -d mongo:4
# 返回容器号
e5d05810c40465559e9b2e516fd9ef60b6d2cb9d96b0fdae3e118acfc074a61e
# 查看容器状态
docker ps
# 输出如下
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5d05810c404 mongo:4 "docker-entrypoint.s…" 33 seconds ago Up 31 seconds 0.0.0.0:27017->27017/tcp mymongo
Shell
docker exec -it mymongo mongo
# 安装mongodb第三方库
brew tap mongodb/brew
# 安装mongodb
brew install mongodb-community@4
# 在全局使用mongo
echo 'export PATH="/usr/local/opt/mongodb-community@4.2/bin:$PATH"' >> ~/.zshrc
# 立即生效
source ~/.zshrc
# 配置路径
/usr/local/etc/mongod.conf
... 待完成