Container migration in Docker [closed]

2019-07-24 19:27发布

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

4条回答
我只想做你的唯一
2楼-- · 2019-07-24 19:57

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

查看更多
祖国的老花朵
3楼-- · 2019-07-24 20:00

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).

echo "{\"experimental\": true}" >> /etc/docker/daemon.json
systemctl restart docker

Step 2: Let's deploy a simple container which print numbers.

docker run -d --name looper --security-opt seccomp:unconfined busybox  \
         /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'

Step 3: Let's verify the application is running by printing the logs.

 docker logs looper

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.

docker checkpoint create looper checkpoint1

Step 4: You can verify the checkpoint in the directory.

/var/lib/docker/containers/<container-ID>/checkpoints/<checkpoint name>/

Step 5: Let's restore the container to the previous state with the following Docker command.

docker start --checkpoint checkpoint1 looper

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

查看更多
你好瞎i
4楼-- · 2019-07-24 20:04

You can export a containet by running

docker export <container-name> -o container.tar

You then can copy the tar into a different VM and import it by running

docker import container.tar <image-name>

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?

查看更多
甜甜的少女心
5楼-- · 2019-07-24 20:07

To export images, use docker save, to import them again, use docker load.

To export containers, use docker export, to import them again (AS IMAGE without Metadata), use docker 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.

查看更多
登录 后发表回答