How to take container snapshots in docker

BackupPortingSnapshotDocker

Backup Problem Overview


How do we take container snapshots and load the snapshot in another docker host . I like to know the container snapshoting and not for image. I get confused with export/import and save/load commands in docker. I like to get more clarity or doc to understand them more deeply .

The snapshot to have the metadata to run the container and the roofs . The exact state to be there in the other docker host. Help in this direction would be great.

Backup Solutions


Solution 1 - Backup

The command docker commit takes a snapshot of your container. That snapshot is an image, which you can put on a (private) repository to be able to pull it on another host.

An option that does not use an image (which you say you want to avoid) is indeed save and load. According to the documentation this saves your container with all file layers. So if you have a setup with child containers such as Ubuntu > JavaJDK > Elasticsearch > my-container, all 4 file layers would get in there. But you may have the first 3 layers already present as images on the other host, in which case save amounts to a lot of overhead. Then, you can use export and import, which according to the documentation only exports the top file layer (in other words, the container, and not the images below it).

More information on the images, container, file layers etc can be found in the official documentation (e.g. file system.

Solution 2 - Backup

If you're looking for an "exact state", including the execution state, you may need to use CRIU (checkpoint).

Given a linux host machine, Docker can use CRIU to save the execution state of the container. CRIU is still "experimental", and you can see all the possible commands (after enabling experimental mode) by running:

docker checkpoint

You can use the --save-dir option to put the checkpoint in the directory of your choosing.

You can then use

docker start --checkpoint (checkpoint name) --checkpoint-dir (checkpoint directory)

to restore the checkpoint.

If moving servers, you may need to bring the image along with you.

You can read more on the docs: https://docs.docker.com/engine/reference/commandline/checkpoint/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontanmallyView Question on Stackoverflow
Solution 1 - BackupqkrijgerView Answer on Stackoverflow
Solution 2 - BackupdGRAMOPView Answer on Stackoverflow