docker backup and restore mongodb

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.


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


    您可以使用此图像为许多作业提供码头容器(导入,导出,转储)

    链接地址: http://www.djcxy.com/p/86566.html

    上一篇: Windows通用响应式设计重新定位

    下一篇: 码头备份和恢复mongodb