Overview
This template provides a production‑ready MongoDB instance as a Monk runnable. You can:- Run it directly to get a managed MongoDB container with sensible defaults
- Inherit it in your own runnable to seamlessly add a document database to your stack
What this template manages
- MongoDB container (
mongoimage, configurable tag) - Network service on port 27017
- Persistent volumes for data storage
- Optional initialization of database, user, and passwords
Quick start (run directly)
- Load templates
- Run MongoDB with defaults
- Customize credentials (recommended via inheritance)
variables. Secrets added with monk secrets add will not affect this runnable unless you inherit it and reference those secrets.
- Preferred: inherit and replace variables with
secret("...")as shown below. - Alternative: fork/clone and edit the
variablesinmongodb/mongodb.yaml, thenmonk load MANIFESTand run.
localhost:27017 (or the runnable hostname inside Monk networks) using the configured credentials.
Configuration
Key variables you can customize in this template:${monk-volume-path}/mongodb on the host.
Use by inheritance (recommended for apps)
Inherit the MongoDB runnable in your application and declare a connection. Example:Ports and connectivity
- Service:
mongodbon TCP port27017 - From other runnables in the same process group, use
connection-hostname("\<connection-name>")to resolve the DB host.
Persistence
- Data path:
${monk-volume-path}/mongodb:/data/db - MongoDB stores all databases and collections in this directory
- Ensure the host volume is writable by the container user
Features
- Document-oriented storage
- Rich query language
- Indexing and aggregation
- Replication and sharding
- ACID transactions
- Change streams
Related templates
- For MongoDB replica set cluster, see
mongodb-cluster/templates - For sharded deployments, check MongoDB sharding templates
- Combine with
mongo-express/for web-based administration
Troubleshooting
- If you changed
mongodb-root-passwordbut the container has existing data, authentication may fail. Either reset the data volume or update the password inside the DB to match. - Ensure the host volumes are writable by the container user.
- Check logs: