Save docker Mongo container with all the data and export it

rvsntn

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 ?

yamenk

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Save Docker container data

Seeding data in a Mongo db within a linked Docker container

Cannot save docker container

How to create a save MySQL container data to a docker image?

Installing mongo client in a Docker container

Export docker container through cloudflared

All Docker container statuses?

does docker support all type on data inside container

How to save a Docker container state

Can't start mongo with docker command, but can with /bin/bash inside container (with data volume)

docker-compose and connection to Mongo container

can`t link mongo docker container

Dump mongo database running on a docker container

How to add volumes to docker mongo container

mongo: command not found on mongodb 6.0 docker container

Run mongo script in deployed docker swarm container

Unable to auth against mongo docker container

Can't connect to docker container with mongo

I m not able to connect to mongo with a container docker

Connecting to mongo docker container from host

Docker-compose: How to connect to mongo container

Spring Data Mongo: How to save batch ignoring all duplicate key errors?

How to export realm file into keycloak docker container?

How to export an Influxdb database which is in a docker container?

Is it safe to export tarball of running docker container?

export the IBM Docker container images in the registry

What is the difference between save and export in Docker?

Connecting to Mongo Docker container from Mongo Compass on local machine?

Export the data from a Mongo DB database in a CSV