An ultra-small Docker image containing MongoDB's mongodump
tool. It enables seamless creation of MongoDB backups without the need to install MongoDB or its dependencies on your system.
- Ultra-small: The image is about 20 MB in size and contains only
mongodump
and its dependencies. - No installation required: You can use
mongodump
without installing MongoDB or its dependencies on your system. - Easy to use: The image can be used as a drop-in replacement for
mongodump
in your backup scripts.
- Docker installed on your machine. That's it.
To create a backup of your MongoDB database, run the following command:
docker run --rm -v /my/backup/folder:/backup chaos/mongo-backup:latest \
--uri mongodb://localhost:27017 \
--db MyDatabase \
--gzip \
--archive=/backup/mybackup.gz
Explanation:
--rm
: Automatically remove the container when it exits.-v /my/backup/folder:/backup
: Mounts the local folder/my/backup/folder/
to the container's/backup
directory.chaos/mongo-backup:latest
: Use the latest version of thechaos/mongo-backup
image.--uri mongodb://localhost:27017
: The MongoDB connection string. You can also usemongodb://username:password@localhost:27017
.--db MyDatabase
: The name of the database you want to dump.--gzip
: Compress the output using gzip.--archive=/backup/mybackup.gz
: Store the backup in a single file namedmybackup.gz
in the container's/backup
directory.
You can also specify the --out
option instead of --archive
to create a directory containing all collections as separate dumps.
See the official MongoDB documentation for more options.
When using this image on the command line or in your backup scripts, especially in multi-user environments, be cautious about exposing sensitive information such as the passwords.
The recommended approach is to provide a YAML configuration for mongodump
containing the connection string:
uri: mongodb://username:password@localhost:27017
Then, run the following command:
docker run --rm -v /my/backup/folder:/backup \
-v /path/to/config.yaml:/config.yaml \
chaos/mongo-backup:latest \
--db MyDatabase \
--gzip \
--archive=/backup/mybackup.gz
MIT License - see LICENSE for more information.