Files
chill_notes/实践积累/个人知识库/Docker/Docker 部署 MongoDB.md
2026-04-21 17:24:50 +08:00

88 lines
1.1 KiB
Markdown
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1.镜像下载
下载 `MongoDB` 镜像命令:
```
```
docker pull mongo
```
```
执行 `docker images` 查看镜像,下载成功,如下图:
2.启动 `MongoDB`
启动 `MongoDB` 命令:
```
```
docker run -p 27017:27017 -v $PWD/db:/data/db -d mongo:latest
```
```
## 命令说明:
```
```
-p 27017:27017 :
```
```
## 将容器的
```
```
27017
```
```
## 端口映射到主机的
```
```
27017
```
```
## 端口
```
```
-v $PWD/db:/data/db :
```
```
## 将主机中当前目录下的**`db`**挂载到容器的
```
```
/data/db
```
```
**,作为**`mongo`**数据存储目录**``
启动成功,如下图:
3.测试连接 `MongoDB`
连接 `MongoDB` 命令:
```
```
docker run -it mongo:latest mongo --host 172.17.0.1
```
```
## 命令说明:
```
```
```
```
## 使用**`mongo`**镜像执行**`mongo` **命令连接到刚启动的容器**`,`**主机**`IP`**为
```
```
172.17.0.1
```
```
提示信息 `It looks like you are trying to access MongoDB over HTTP on the native driver port.` nice部署 `MongoD` 成功!