How to clone/snapshot a Docker container with all data?

Asked

Viewed 678 times

0

I’m trying to make a clone or snapshot of a container Docker and all its contents.

More specifically, I have two containers where databases run, one with Cassandra and another with MySQL. They are used in tests, so I would like to get a Snapshot of this and copy in another container to be able to use without "spoiling" the original, but I did not succeed in doing so.

Searching for backups/clone/snapshots of containers, I reached the commands Docker commit and Docker save that saves the image and then can be loaded in another container, but I did not succeed with both.

What happens is that I can copy and even settings, but not the data of the instances of the banks, it comes empty.

I could generate scripts to do this, and every time I need to create a new container and run the scripts, but I believe that a clone/snapshot would be simpler and seems to me something trivial, only I don’t know how to do :(

So my question is: how to take a backup or snapshot of a Docker container and create a new one, keeping the data, especially the data of a container with a database, its tables and data?

  • How do you want to backup the container data docker cp wouldn’t solve this? Ideally you would use volumes, hence would keep your data persistence...

  • but using the docker cp i need to inform the folders/files I want to copy right? I would like something simpler as if it were docker cp cointainer-origem to container-destino

  • I get it, via Docker I don’t know a Feature that does that :/

  • creates a checkpoint https://docs.docker.com/engine/reference/commandline/checkpoint/

  • @Adirkuhn read the link from the command, and this is an experimental command right? but the question is: create the checkpoint, and then restore on another machine?

1 answer

2


The idea of a container is exactly this, not having to create clones or snapshots, this is the function of a VM.

As stated in the comments, the best way is to use the command docker cp found in that link, taking the necessary files using /path/to/file:name.txt or ./file:name.txt.

Another option is to make one Dump of their bases Mysql and your Cassandra.

As good practice, the correct thing is to assemble a local volume with your base and direct your container to that volume.

  • "The idea of a container is exactly that", That’s a point to think I hadn’t thought of that way, I don’t accept the idea of not being able to "clone" a complete container, and it seems to me that it’s a situation that can happen to other people. Anyway, I’ll test the command docker cp, but I guess that’s not practical: I, as a Veloper, know how to use sql commands, configure the database, etc, but I have no idea where the database files are to copy them, and more, if only copy works? with sql-server and oracle that I know a little more not, have to register

  • so although possibly allow copying, it is not a solution, probably would have to write a script that does all the work, and has to know the folder/file structure of the MySql and of Cassandra. But if you can’t handle it, that’s the way it’s gonna be :)

  • At this link: https://hub.docker.com//mysql more specifically in Where to Store Data, shows exactly where your base directory is to use the docker cp, the same works for the Cassandra at https://hub.docker.com//Cassandra

  • If you would like to use a Docker statically for your information, I recommend reading https://www.infoworld.com/article/3106416/containerizing-stateful-applications.html

  • although I have not resolved exactly what I would like, it is as close as I could

Browser other questions tagged

You are not signed in. Login or sign up in order to post.