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 ?
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:
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