-
Notifications
You must be signed in to change notification settings - Fork 0
⭐ StartMongodb
StartMongodb StartMongodb is the provisioning action responsible for launching MongoDB containers with secure defaults, persistent volumes, keyfile authentication, optional TLS/SSL support, engine‑specific environment variables, and predictable startup behavior. MongoDB is more complex than SQL engines because it requires keyfile authentication and has unique directory structures and runtime flags.
This page explains how StartMongodb works, what it generates, and how it fits into the broader provisioning system.
Purpose of StartMongodb The StartMongodb action handles all logic required to start a MongoDB instance, including:
Validating configuration
Generating SSL certificates
Creating persistent volumes
Generating MongoDB keyfile authentication
Building environment variables
Generating Docker Compose
Applying MongoDB‑specific runtime flags
Configuring healthchecks
Starting the container
It ensures MongoDB is provisioned consistently and securely across all deployments.
MongoDB‑Specific Requirements MongoDB has several unique requirements that differ from SQL engines:
- Keyfile Authentication MongoDB requires a keyfile when authentication is enabled.
This file:
Must be generated
Must have strict permissions
Must be mounted into the container
Must be referenced via --keyFile
Your StartMongodb action handles this automatically.
- SSL/TLS Configuration If SSL is enabled, MongoDB requires:
CA certificate
Server certificate
Server key
TLS configuration flags
MongoDB uses:
Code --tlsMode --tlsCertificateKeyFile --tlsCAFile 3. Data Directory MongoDB stores data in:
Code /data/db This directory is mapped to a persistent volume.
- Config Directory MongoDB may require:
Keyfile directory
SSL directory
Custom config directory
StartMongodb generates and mounts these automatically.
StartMongodb Lifecycle mermaid flowchart TD A[StartMongodb] --> B[Validate Configuration] B --> C[Generate SSL Certificates] C --> D[Generate Keyfile Authentication] D --> E[Generate Persistent Volumes] E --> F[Build Environment Variables] F --> G[Generate Docker Compose] G --> H[Start MongoDB Container]
- Validate Configuration StartMongodb checks:
Port availability
Keyfile requirements
Volume paths
SSL/TLS settings
Custom runtime options
MongoDB is strict — missing keyfiles or incorrect permissions will prevent startup.
- Generate SSL Certificates (Optional) If TLS is enabled:
A CA certificate is generated
A server certificate is generated
A server key is generated
Certificates are mounted into the container
MongoDB is configured to use TLS
Certificates are stored under:
Code /data/coolify/ssl// 3. Generate Keyfile Authentication MongoDB keyfile authentication includes:
Generating a secure keyfile
Setting strict permissions (600)
Mounting the keyfile into the container
Passing --keyFile to the MongoDB runtime
Keyfiles are stored under:
Code /data/coolify/mongodb//keyfile 4. Generate Persistent Volumes Using GeneratesLocalPersistentVolumes, StartMongodb creates:
Local data directory
SSL directory
Keyfile directory
Config directory
Volumes are mapped into the container:
Code /data/db /etc/mongodb/ssl /etc/mongodb/keyfile /etc/mongodb/conf This ensures MongoDB persistence across restarts.
- Build Environment Variables MongoDB uses fewer environment variables than SQL engines, but StartMongodb still builds:
Optional Code MONGO_INITDB_ROOT_USERNAME MONGO_INITDB_ROOT_PASSWORD System Internal variables required for provisioning.
SSL If TLS is enabled:
Code MONGO_SSL_CA MONGO_SSL_CERT MONGO_SSL_KEY 6. Generate Docker Compose StartMongodb generates a full Compose service definition including:
Image Code mongo: Ports Code 27017:27017 Volumes Data directory
SSL directory
Keyfile directory
Config directory
Environment Variables All normalized variables.
Healthcheck MongoDB healthcheck typically uses:
Code mongo --eval "db.adminCommand('ping')" Runtime Options MongoDB‑specific flags such as:
--auth
--keyFile
--tlsMode
--tlsCertificateKeyFile
--tlsCAFile
- Start the Container The generated Compose file is passed to the provisioning engine, which:
Creates the container
Applies resource limits
Connects networks
Starts MongoDB
Verifies healthcheck
Marks the database as running
Example Compose Snippet (Conceptual example — your implementation generates this dynamically.)
Code services: mongodb: image: mongo:7 ports: - "27017:27017" environment: MONGO_INITDB_ROOT_USERNAME: "${MONGO_INITDB_ROOT_USERNAME}" MONGO_INITDB_ROOT_PASSWORD: "${MONGO_INITDB_ROOT_PASSWORD}" volumes: - /data/coolify/mongodb//data:/data/db - /data/coolify/ssl/:/etc/mongodb/ssl - /data/coolify/mongodb//keyfile:/etc/mongodb/keyfile command: - --auth - --keyFile=/etc/mongodb/keyfile/keyfile - --tlsMode=requireTLS - --tlsCertificateKeyFile=/etc/mongodb/ssl/server.pem - --tlsCAFile=/etc/mongodb/ssl/ca.pem healthcheck: test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"] interval: 10s timeout: 5s retries: 5 Why StartMongodb Is Important StartMongodb ensures:
Secure defaults
Predictable provisioning
Keyfile authentication
SSL/TLS support
Persistent storage
Clean environment variable handling
Consistent Docker orchestration
MongoDB is one of the most complex engines to provision, and StartMongodb handles all of its unique requirements.