Installing MongoDB 8 in Docker on a Plesk Server

Learn how to deploy MongoDB 8 on a Plesk server using Docker three ways: the Plesk GUI, the CLI, and Docker Compose. This guide standardizes on bind mounts under a dedicated subscription, shows single-instance first, then scales to multiple instances with host-only access, backup recipes, and ops tips.

Table of Contents

MongoDB is a document-oriented database built for agility and scale. Instead of rigid rows and columns, it stores JSON-like documents (BSON) with dynamic schemas. That flexibility shines for content systems, event logs, product catalogs, user profiles, and IoT telemetry—anywhere the data shape evolves quickly or varies record-to-record. MongoDB emphasizes horizontal scaling (sharding), high availability (replica sets), and developer ergonomics (rich drivers, expressive queries, and aggregation pipelines).

On a Plesk server, the cleanest way to run MongoDB is in Docker. You isolate the database from the host OS, get reproducible deployments, and upgrade by swapping images. Below are three approaches—choose based on your workflow:

  • Option A (Plesk GUI) – Use the Docker extension UI.
  • Option B (CLI) – Full control from the shell.
  • Option C (Compose/Stacks) – One YAML per instance, ideal for multi-instance hosts with host-only access.

We’ll use the official mongo:8 image throughout.


What you’ll need

Storage convention used in this guide

Plesk’s Docker UI naturally favors bind mounts. While bind mounts aren’t ideal for every scenario (named volumes can be more portable and safer against path typos), we’ll use bind mounts for consistency across all three options in this article.

We’ll create a Plesk subscription (domain) named mongodb.acme.com and store data/config here:

  • Data: /var/www/vhosts/mongodb.acme.com/mongodb/data
  • Config: /var/www/vhosts/mongodb.acme.com/mongodb/config

You can adapt these paths to your own subscription/domain structure.

  • Plesk Obsidian with administrator/root access
  • Docker (Plesk Docker extension)
  • ~2–4 GB RAM minimum for a small dev instance (more for production)
  • Optional: Plesk Firewall (or OS firewall) if you expose MongoDB (most apps don’t need this)

Production tip: Only expose MongoDB publicly if you absolutely must. Prefer no published port or bind to loopback (127.0.0.1) when the app is on the same host.


Architecture choices (decide these up front)

  • Persistence → Mount a host path or Docker volume to /data/db.
  • Auth → Always set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD.
  • Networking
    • Plesk GUI: relies on Docker’s default bridge.
    • CLI/Compose: create a user-defined bridge per app for private DNS (mongo:27017).
  • Exposure → Prefer not publishing 27017. If host access is required, bind to 127.0.0.1:<unique-port>.
  • Multi-instance → Use unique names, data volumes/paths, networks, and ports per instance.

Option A — Plesk GUI (Docker extension)

Prepare the subscription and directories (once)

  1. In Plesk, create a subscription (domain) named mongodb.acme.com (or use an existing subscription).
  2. On the server (SSH):

Recent Plesk Obsidian builds don’t have global “Docker → Volumes/Networks.” You configure volume mappings inside the container’s settings; networking defaults to Docker’s bridge.

A1) Single instance (GUI)

Deploy container:

  1. Extensions → Catalog → Docker (install/enable if needed).
  2. Docker → Add Container (or search mongo in Images) → choose mongo:8.
  3. Container Settings:
    • Container name: mongo
    • Env:
      MONGO_INITDB_ROOT_USERNAME=rp_admin
      MONGO_INITDB_ROOT_PASSWORD=ChangeMe-Use-A-Strong-One
    • Volume mapping (bind mounts):
      • /var/www/vhosts/mongodb.acme.com/mongodb/data/data/db
      • /var/www/vhosts/mongodb.acme.com/mongodb/config/data/configdb
    • Ports:
      • Prefer none (private), or
      • Host access: 127.0.0.1:27017 → 27017
    • Automatic start: enabled
    1. Run.

Connect from host (if port bound):

A2) Multiple instances (GUI)

Create instance-specific directories:

Repeat the deploy with unique settings per instance:

  • Names: mongo-store, mongo-auth
  • Volume mappings:
    • Store:
      • /var/www/vhosts/mongodb.acme.com/mongodb/store/data/data/db
      • /var/www/vhosts/mongodb.acme.com/mongodb/store/config/data/configdb
    • Auth:
      • /var/www/vhosts/mongodb.acme.com/mongodb/auth/data/data/db
      • /var/www/vhosts/mongodb.acme.com/mongodb/auth/config/data/configdb
  • Ports (host-only):
    • 127.0.0.1:27018 → 27017 (store)
    • 127.0.0.1:27019 → 27017 (auth)

Host connection strings:


Option B — CLI (fine-grained control)

Prepare the subscription and directories (once)

B1) Single instance (CLI)

Run container (bind mounts, private, no published port):

(If host access needed) bind loopback:

Create app user (inside container):

App container (same network):

B2) Multiple instances (CLI)

Per instance directories:

Per instance networks:

Mongo containers (bind mounts, no public ports):

(If host access needed) bind unique loopback ports:

Optional hard limits to avoid noisy neighbors: add --cpus="1.5" --memory="2g" --memory-swap="2g".
Optional cache tuning: --wiredTigerCacheSizeGB 1.

Option C – Docker Compose (Plesk Stacks)

Goal: Multiple independent MongoDB 8 instances, each with its own docker-compose.yml directory, each bound to a unique loopback port for host-only access, using bind mounts under the mongodb.acme.com subscription.

Prepare the subscription and directories (once)

C1) Single instance (Compose)

Directory layout

.env

docker-compose.yml

Create the stack in Plesk

  • Extensions → Docker → Stacks → Add Stack, point to /var/www/vhosts/mongodb.acme.com/mongodb/auth/docker-compose.yml.
  • If .env wasn’t auto-loaded, set variables in the Stack UI or add env_file.

Start via CLI (alternative to Plesk Stacks)

Host connection


C2) Multiple instances (Compose)

Directories

/var/www/vhosts/mongodb.acme.com/mongodb/store/.env

/var/www/vhosts/mongodb.acme.com/mongodb/store/docker-compose.yml

/var/www/vhosts/mongodb.acme.com/mongodb/auth/.env

/var/www/vhosts/mongodb.acme.com/mongodb/auth/docker-compose.yml

Start via CLI (per instance)

Host connection strings

Backups (all options)

Logical dumps with mongodump

  • Networked (B/C without host ports): run a throwaway mongo:8 container on the same Docker network as the DB and target mongo:27017.
  • Host-bound (A/C multi-instance): run the backup container with --network host and target 127.0.0.1:<port>.

Examples (host-bound, multi-instance):

Restore test (monthly)

Spin up a temporary Mongo, create a root user, and mongorestore from one of the dated folders.


Upgrades & maintenance

  • Minor updates
    • A: Stop/remove container in UI, re-run with same settings after mongo:8 is pulled (or recreate via UI).
    • B: docker pull mongo:8 && docker stop mongo && docker rm mongo then recreate with the same flags.
    • C: Per instance dir: docker compose pull && docker compose up -d.
  • Major upgrades: Read release notes and test on a copy of data.
  • Logs: docker logs -f <container>
  • Resources: Monitor disk and memory; WiredTiger needs headroom.

Troubleshooting quick hits

  • “Authentication failed” → Ensure authSource matches the DB that holds the user (often not admin).
  • “Connection refused” → Same network (B/C) and use container name (mongo, mongo-store) or correct host port.
  • High CPU at idle → Investigate unindexed queries; create indexes with db.collection.createIndex(...).
  • Permission denied on data path → If bind-mounting, ensure the host directory is writable by MongoDB’s UID/GID inside the container (UID 999).

Which option should I use?

Need / Constraint Option A (GUI) Option B (CLI) Option C (Compose per instance)
Fastest single instance
Private app↔DB without exposing ports ⚠️ (awkward) ✅ user-defined networks ✅ if you also define the app service/network
Many isolated instances on one host 😬 manual UI work ✅ straightforward per network/volume/name ✅ best: one compose dir (YAML + .env) each
Host-only access (loopback) per instance ✅ per-container mapping -p 127.0.0.1:PORT:27017 ✅ best via ports: "127.0.0.1:${PORT}:27017"
Source control & repeatability ⚠️ scripts commit each instance’s YAML & .env

Wrap-up

You now have three clean paths to run MongoDB 8 in Docker on a Plesk server—each showing the single-instance flow first and the multi-instance pattern second. For multi-instance hosts with host-only access, Option C (one compose per instance with the port in .env) is tidy, repeatable, and easy to operate.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.