系统环境
ubuntu 18.04
docker(我的version 是docker-ce 20.10.14)
安装crui
参考1:https://gist.github.com/justincormack/1902f2eb7ac085fa69a8577a70c6f27f
依赖包安装
apt update
apt upgrade
apt install build-essential
apt install pkg-config
apt install libnet-dev python-yaml libaio-dev
apt install libprotobuf-dev libprotobuf-c0-dev protobuf-c-compiler protobuf-compiler python-protobuf libnl-3-dev libcap-dev python-future
安装criu
curl -O -sSL http://download.openvz.org/criu/criu-version.tar.bz2 #我装的3.16
tar xjf criu-version.tar.bz2
cd criu-3.10
make
cp ./criu/criu /usr/local/bin
检查criu是否装好
配置docker
echo "{\"experimental\": true}" >> /etc/docker/daemon.json
systemctl restart docker
容器热迁移例子
参考1:https://zhuanlan.zhihu.com/p/269552404(docker start --checkpoint-dir)这一步可能会报错。解决办法见参考2中的issue
参考2:https://github.com/moby/moby/issues/37344
创建容器looper2
docker run -d --name looper2 --security-opt seccomp:unconfined busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'
看下日志
docker checkpoint create --checkpoint-dir=***** looper2 checkpoint2
执行这句之后looper2容器会停止运行
创建迁移后的容器
docker create --name looper-clone --security-opt seccomp:unconfined busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'
可能会报错的地方
docker start --checkpoint-dir=/home/xty/container/checkpoint2/ --checkpoint=checkpoint2 looper-clone
根据参考2,解决办法为
mv /home/xty/container/checkpoint2/ /var/lib/docker/containers/5e1b38c17d42a8382596bf0c631c52d9486627b75df588557a85c27e8b62b93e/checkpoints
docker start --checkpoint=checkpoint2 looper-clone
看一下容器迁移后的日志: