MongoDB — the popular general-purpose document database. Deployed as a single host-networked Nomad service with authentication enabled.
Needs nomad-pack on PATH. The script only adds the nomploy registry and runs this pack.
Source ↗ Project ↗ ★ 28.6k ⚑ Report an issue
Save as values.hcl, edit, then run:
# The name of the Nomad job.
job_name = "mongodb"
# The Nomad namespace to deploy into.
namespace = "default"
# The datacenters to deploy to.
datacenters = ["*"]
# The MongoDB container image (5.0+ needs a CPU with AVX). Pin a tag in production.
image = "mongo:7.0"
# Host port for MongoDB.
port = 27017
# Root username created on first start.
root_username = "root"
# Root password created on first start. CHANGE THIS.
root_password = "mongodb_change_me"
# Named volume for MongoDB data (/data/db).
data_volume = "mongodb_data"
# Placement constraints. On a nomploy cluster: attribute = "$${meta.nomploy_control_plane}", operator = "=", value = "true".
constraints = []
# The task resources.
resources = {
cpu = 500
memory = 1024
}
| Name | Type | Default | Description |
|---|---|---|---|
| job_name | string | "mongodb" | The name of the Nomad job. |
| namespace | string | "default" | The Nomad namespace to deploy into. |
| datacenters | list | ["*"] | The datacenters to deploy to. |
| image | string | "mongo:7.0" | The MongoDB container image (5.0+ needs a CPU with AVX). Pin a tag in production. |
| port | number | 27017 | Host port for MongoDB. |
| root_username | string | "root" | Root username created on first start. |
| root_password set me | string | "mongodb_change_me" | Root password created on first start. CHANGE THIS. |
| data_volume | string | "mongodb_data" | Named volume for MongoDB data (/data/db). |
| constraints | list | [] | Placement constraints. On a nomploy cluster: attribute = "$${meta.nomploy_control_plane}", operator = "=", value = "true". |
| resources | object | {
cpu = 500
memory = 1024
} | The task resources. |
No variables match.
This pack stores data in one Docker named volume:
mongodb_data
⚠ This pack bundles a database. A cold copy of the volume can be inconsistent — for a reliable backup, dump the DB (pg_dump / mysqldump) or stop the job while backing up.
restic
# Run on the node hosting this pack. Point restic at your repo first: # export RESTIC_REPOSITORY="s3:https://<account>.r2.cloudflarestorage.com/<bucket>" # export RESTIC_PASSWORD="<repo-password>" # export AWS_ACCESS_KEY_ID=<key> AWS_SECRET_ACCESS_KEY=<secret> restic backup \ /var/lib/docker/volumes/mongodb_data/_data
rclone (sync to S3/R2)
rclone sync /var/lib/docker/volumes/mongodb_data/_data backup:<bucket>/mongodb_data
Paths assume the default Docker volume location (/var/lib/docker/volumes). Restore by stopping the job, restoring files into the same volume, and re-running the pack.
MongoDB is a widely used, general-purpose document (NoSQL) database. It stores flexible JSON-like documents, scales horizontally and is the backend for a huge range of self-hosted applications.
This pack runs a single MongoDB instance as a host-networked Nomad service with authentication enabled via a root account.
nomad-pack run mongodb --registry=nomploy \
--var root_password=$(openssl rand -hex 16)
Connect with mongodb://root:<password>@<node-ip>:27017/?authSource=admin.
| Variable | Default | Description |
|---|---|---|
image |
mongo:7.0 |
Container image (5.0+ needs AVX; pin a tag). |
port |
27017 |
Host port for MongoDB. |
root_username |
root |
Root username created on first start. |
root_password |
mongodb_change_me |
Root password — change this. |
data_volume |
mongodb_data |
Volume for data (/data/db). |
resources |
500 MHz / 1024 MB | CPU and memory for the task. |
Note: MongoDB 5.0+ requires a CPU with AVX support. On older CPUs, pin
imagetomongo:4.4.
Data persists in data_volume. The root account is created only on the very
first start (when the data directory is empty).