generated from ztimson/template
f81e6cd95196f57a3f3e775fe0df1ee7c8a2fa83
All checks were successful
Build and publish / Build Container (push) Successful in 1m47s
Table of Contents
About
Custom MongoDB Docker image extending mongo:latest with automated backups, retention management, and replica set configuration.
Includes cron-based scheduled mongodump operations with compression, automatic stale lock recovery on unclean shutdowns, and zero-config replica set initialization — while preserving all native MongoDB functionality.
Manually trigger a backup: docker exec -t mongodb backup
Restore a backup:
Decompress the archive and use the official mongorestore tool.
Environment Variables
| Variable | Description | Default | Example |
|---|---|---|---|
BACKUP_CRON |
Cron schedule expression | 0 */6 * * * |
|
BACKUP_DIR |
Directory to store backups | /data/backups |
/backups |
BACKUP_DB |
Database to backup | $MONGO_INITDB_DATABASE |
admin |
BACKUP_RETENTION |
Number of backups to keep, defaults to unlimited | 7 |
|
MONGO_INITDB_DATABASE |
Default database name | momentum |
|
MONGO_INITDB_ROOT_USERNAME |
Root username for mongodump auth | root |
|
MONGO_INITDB_ROOT_PASSWORD |
Root password for mongodump auth | secret |
|
REPLICA |
Comma-separated list of replica hostnames to init/join a replica set | db1:27017,db2:27017 |
Built With
Setup
Production
Prerequisites
Instructions
- Run the docker image:
docker run -d \
--name mongodb \
--restart unless-stopped \
-p 27017:27017 \
-e MONGO_INITDB_DATABASE=myapp \
-e BACKUP_CRON="0 3 * * *" \
-e BACKUP_RETENTION=7 \
-v ./mongodb/data:/data/db \
-v ./mongodb/backups:/data/backups \
ztimson/mongodb:latest
Languages
Shell
86.4%
Dockerfile
13.6%