# Self-host MongoDB

> The MongoDB document database on the official image, with a persistent volume and a generated root user and password. It is not published on the host, so reach it from other services in this project at mongodb:27017.

- Page: https://levelrail.com/templates/mongodb/
- JSON: https://levelrail.com/templates/mongodb.json
- Category: Database Tools
- Licence: LicenseRef-SSPL-1.0 (Source available)
- Source: https://github.com/mongodb/mongo
- Upstream docs: https://www.mongodb.com/docs/manual/

## Requirements
- Memory: about 512 MiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 8.0.34

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| mongodb | mongo | 8.0.34 | 27017 | mongodb_data -> /data/db; mongodb_config -> /data/configdb |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| mongodb | MONGO_INITDB_ROOT_PASSWORD | generated |
| mongodb | MONGO_INITDB_ROOT_USERNAME | generated |

## Deploy

### CLI

```bash
levelrail-cli templates deploy mongodb --name my-mongodb
```

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" \
  https://levelrail.example.com/api/v1/service-templates/mongodb/deploy
```

Create a token in the dashboard first. This one-click route deploys it as a trial app you can keep or remove.

## First run
1. Read the generated root user and password from the app secrets, then connect from a service in the same project with mongodb://USER:PASSWORD@mongodb:27017/?authSource=admin.

## Questions

### Can I deploy MongoDB on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for MongoDB, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image mongo:8.0.34 is what you deploy there.

Self-host MongoDB, MongoDB docker compose file, deploy MongoDB on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
