Create data only container:
docker create -v /mongodb_data --name mongodb_data mongo
Create monogdb container:
docker run --volumes-from mongodb_data --name mongo_db --restart always -d mongo
Then to use mongodb in my own container I use the link command:
--link mongo_db:mongo
So everything works fine. Now I want to backup the mongodb according to the docs: http://docs.docker.com/userguide/dockervolumes/#backup-restore-or-migrate-data-volumes and this command:
docker run --volumes-from mongodb_data -v $(pwd):/backup busybox tar cvf /backup/backup.tar /mongodb_data
However the created tar file has just an empty /mongodb_data
folder. The folder contains not a single file.
Any ideas whats wrong? I am using docker 1.7 on ubuntu 14.04 LTS.
MongoDB can be run in a Docker container. There is an official image available on Docker Hub containing the MongoDB community edition, used in development environments. For production, you may custom-build a container with MongoDB's enterprise version.
The Mongodump command dumps a backup of the database into the “. bson” format, and this can be restored by providing the logical statements found in the dump file to the databases. The Mongorestore command is used to restore the dump files created by Mongodump.
The problem is your data only container. You make your volume with path /mongodb_data
which doesn't store any mongo db data. By default, the mongo db storage path is /data/db
(according to this #Where to Store Data Section)
As the result, your mongodb data is not saved in your data only container. So here is a workaround:
copy /data/db
to /mongodb_data
in your mongodb container docker exec -it mongo_db bash
then cp -r /data/db/* /mongodb_data/
make a backup by following the doc you mentioned
build a new data only container and load the backup
mongo_db
container and recreate a new one with the new data only containerOR, you can modify your mongodb
config, to change the default directory to /mongodb_data
once you copied all data from /data/db
to /mongodb_data
. You may find this useful Changing MongoDB data store directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With