Nomploy Nomad Packs

← All packs

mongodb v0.1.0

Databases

MongoDB — the popular general-purpose document database. Deployed as a single host-networked Nomad service with authentication enabled.

nomad-pack run mongodb --registry nomploy
…or one line (add registry + run)
curl -fsSL https://packs.nomploy.com/install.sh | sh -s -- mongodb

Needs nomad-pack on PATH. The script only adds the nomploy registry and runs this pack.

1 task mongo 27017 1 volume image mongo:7.0 pinned :7.0 image bumped today
Variables 10
values.hcl

Save as values.hcl, edit, then run:

nomad-pack run mongodb -f values.hcl --registry nomploy
# 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
  }
NameTypeDefaultDescription
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.
Back up this pack

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.

Readme

mongodb

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.

Deploy

nomad-pack run mongodb --registry=nomploy \
  --var root_password=$(openssl rand -hex 16)

Connect with mongodb://root:<password>@<node-ip>:27017/?authSource=admin.

Configuration

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 image to mongo:4.4.

Data persists in data_volume. The root account is created only on the very first start (when the data directory is empty).