> For the complete documentation index, see [llms.txt](https://hezhiqiang.gitbook.io/docker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hezhiqiang.gitbook.io/docker/appendix/repo/mongodb.md).

# MongoDB

## 基本信息

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

该仓库位于 `https://hub.docker.com/_/mongo/` ，提供了 MongoDB 2.x \~ 4.x 各个版本的镜像。

## 使用方法

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

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

使用其他应用连接到容器，可以用

```bash
$ docker run --name some-app --link some-mongo:mongo -d application-that-uses-mongo
```

或者通过 `mongo`

```bash
$ docker run -it --rm \
    --link some-mongo:mongo \
    mongo \
    sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
```

## Dockerfile

请到 <https://github.com/docker-library/docs/tree/master/mongo> 查看。
