# MongoDB

## 基本信息

[MongoDB](https://en.wikipedia.org/wiki/MongoDB) 是开源的 NoSQL 数据库实现。

该仓库位于 `https://hub.docker.com/_/mongo/`。具体可用版本以 Docker Hub 上的 tags 列表为准。

## 使用方法

默认会在 `27017` 端口启动数据库。

```bash
$ docker run --name mongo -d mongo
```

使用其他应用连接到容器，首先创建网络

```bash
$ docker network create my-mongo-net
```

然后启动 MongoDB 容器

```bash
$ docker run --name some-mongo -d --network my-mongo-net mongo
```

最后启动应用容器

```bash
$ docker run --name some-app -d --network my-mongo-net application-that-uses-mongo
```

或者通过 `mongosh`（MongoDB 6.0+ 已移除旧版 `mongo` 命令行工具）

```bash
$ docker run -it --rm \
    --network my-mongo-net \
    mongo \
    mongosh "some-mongo:27017/test"
```

## Dockerfile

请到 [Mongo 官方镜像文档目录](https://github.com/docker-library/docs/tree/master/mongo) 查看。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/docker_practice/fu-lu/appendix/repo/mongodb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
