rvsntn
rvsntn

Reputation: 85

Save docker Mongo container with all the data and export it

I have created a docker image with a container of Mongo.

My database is filled with data, up to 35 GB.

I want to be able to export it (tar file for example) with all the data inside, and to import to another docker-machine without losing any data.

When using docker save, I couldn't find any information on the statut of saving up data ...

What is the best method to save a fully functionnal container and import it to another docker-machine ?

Upvotes: 2

Views: 4134

Answers (2)

yamenk
yamenk

Reputation: 51738

To export a container:

docker export --output="container.tar" <container-name>

This will export your container to container.tar which can be imported back on another machine using:

docker import container.tar <container-name>.

However, as stated in the docker export docs:

The docker export command does not export the contents of volumes associated with the container. If a volume is mounted on top of an existing directory in the container, docker export will export the contents of the underlying directory, not the contents of the volume.

Now mongo exposes /data/db and /data/configdb as volumes. Thus they will not be exported with the tar ball. Thus the data and config won't be in the tar :(

VOLUME /data/db /data/configdb

What you need to do in order to get this data is either one of the follow:

  1. How to port data-only volumes from one host to another?

  2. Copy these folders form inside the container manually and copy them back to the new container when your import it from the tar.

    docker cp :/data/db ./data docker cp :/data/configdb ./config

Copy these folder to the new host, then import the tarred container and finally copy back these folder into the container

docker cp data/* <new-container>:/data/db
docker cp config/* <new-container>:/data/configdb

Upvotes: 4

sanath meti
sanath meti

Reputation: 6519

To view the status of docker save u need to use --output ex:. docker save --output imagename > imagename.tar. u cannot save container only image can be saved. In order to save container data u need to commit n launch from committed container

Upvotes: 0

Related Questions