I am searching for a simple tutorial to test container migration between two VMs. I have seen some videos but they do not show exactly how they did that or didn't actually found any good tutorial by myself. I am new to docker so I just wanted to test how this migration works. So, it will be very nice you can give me some tutorials/links that clearly explains how to do it. Your help will be really appreciated, thanks :)
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
You can use checkpoint/restore tools like CRIU. https://criu.org/Live_migration You need to checkpoint all processes and memory status of your container before migrating it to another host. In the receiver host you need to create the same container and then restore the checkpoint that you have transmitted. check these out:
https://circleci.com/blog/checkpoint-and-restore-docker-container-with-criu/
https://criu.org/Docker
https://forums.docker.com/t/docker-checkpoint-restore-on-another-host/27427/3
I really endorse Farhood's answer. I want to write here in detail. At First, Docker supports "checkpoint and restore" of a contianer, thanks to the CRIU integration with Docker. But, it is in the experimental mode so be careful.
What is CRIU? CRIU is a software tool for the Linux operating system. with this tool, you can freeze a running application (or part of it) and checkpoint it as a collection of files on disk. You can then use the files to restore the application and run it exactly as it was during the time of the freeze.
Application of Checkpoint/Restore
With this, you can checkpoint an application and copy the files(from checkpoint) to the target machine and start the application using the files which is known as live migration,
You can take a checkpoint of an application and restore the application in the previous state which is nothing but the snapshotting.
"Checkpointing and restoring" can be used in debugging of an application. all processes of the application are checkpointed just before a bug and later restarted (possibly on a single host) for debugging.
Optimize boot time: Checkpoint the boot process of an OS and next time, this checkpoint can be used to start an OS.
Currently, CRIU is the only tool available to checkpoint and restore a container. I'll show you simple steps for the above operation.
Step 1: Enable experimental features (incl. CRIU).
Step 2: Let's deploy a simple container which print numbers.
Step 3: Let's verify the application is running by printing the logs.
Step 4: Let's checkpoint this container with the following
Docker
command. Name of the checkpoint is "checkpoint1". We will use this name to restore the container.Step 4: You can verify the checkpoint in the directory.
Step 5: Let's restore the container to the previous state with the following
Docker
command.Step 6: How to verify? Print the logs of the container before and after the step 5.
(Container migration)How to restore the container in different VM? The solution is to copy the checkpointed files(of the container) to the target node and use them to restore the container. The target node should have Docker running in the experimental mode.
I am attaching hereby a recent paper on Docker container migration. You are looking for this paper.
http://www.cs.toronto.edu/~sahil/suneja-icdcs17.pdf
You can export a containet by running
You then can copy the tar into a different VM and import it by running
WARNINIG:
The export does not export mounted volumes as part of the tarball. Check the documentation for more info.
If you have a volume and you want to migrate it to the new VM, check How to port data-only volumes from one host to another?
To export images, use
docker save
, to import them again, usedocker load
.To export containers, use
docker export
, to import them again (AS IMAGE without Metadata), usedocker import
.You can find out more about the commands and how to use them with
docker COMMAND --help
.Sadly you can't migrate running containers, so I advise you to note down the
docker run
commands you've used to start the containers and then start them again on the other node.