8

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.

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

2 Answers2

8

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

  • remove current mongo_db container and recreate a new one with the new data only container

OR, 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

depperm
  • 10,606
  • 4
  • 43
  • 67
Freeznet
  • 537
  • 2
  • 6
0

You can use this image that provides docker container for many jobs ( import, export , dump )

bwnyasse
  • 591
  • 1
  • 10
  • 15