Docker - 无法检查点容器

时间:2018-02-07 22:46:36

标签: docker containers checkpoint

我正在尝试在busybox图像中使用检查点。起初我创建了一个常规循环然后打印数字。

docker run -d --name simple13 busybox /bin/sh -c "i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done"

docker logs -f simple13

然后我尝试按照命令 -

使用检查点
docker checkpoint create simple13 checkpoint1

但是,它显示了一些像这样的错误 -

    Error response from daemon: Cannot checkpoint container simple13: 
docker-runc did not terminate sucessfully: CRIU version check failed: exec: 
"criu": executable file not found in $PATH path= 
/var/run/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/2fd6f5b517
3fb75ee2793d50602506ee6bc97fcd49df93141846fec21f003be4/criu-dump.log: unknown

这里已经开启了实验。那么,请告诉我在这里需要做什么才能正确使用检查点?谢谢。

λ docker version
Client:
 Version:       17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:05:22 2017
 OS/Arch:       windows/amd64

Server:
 Engine:
  Version:      17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:        Wed Dec 27 20:12:29 2017
  OS/Arch:      linux/amd64
  Experimental: true

1 个答案:

答案 0 :(得分:1)

bash变量扩展存在问题。通过CMD的方式将继续打印空行,而不是数字。查看命令最终如何设置到容器(结果是docker container inspect ...输出的一部分:

"Cmd": [
    "/bin/sh",
    "-c",
    "i=0; while true; do echo ; i=1; sleep 1; done"
], 

我改变了一些引号的使用,以下打印数字:

docker run -d --name simple13 busybox /bin/sh -c 'i=0; while true; do echo "$i"; i=$(expr "$i" + 1); sleep 1; done'

请注意Cmd docker container inspect simple13 "Cmd": [ "/bin/sh", "-c", "i=0; while true; do echo \"$i\"; i=$(expr \"$i\" + 1); sleep 1; done" ], 结果中的差异:

docker checkpoint create simple13 checkpoint1

关于sudo apt-get install criu 错误:

对我来说,使用后它已经解决了:

ubuntu@ubuntu:~$ docker run -d --name simple13 busybox /bin/sh -c 'i=0; while true; do echo "$i"; i=$(expr "$i" + 1); sleep 1; done'
1ffd1f30aec96e07ac7c229c581b7ccd5feb9d180602eeb663211189abc652e4
ubuntu@ubuntu:~$ docker logs simple13 
0
1
2
3
ubuntu@ubuntu:~$ docker checkpoint create simple13 checkpoint1
checkpoint1
ubuntu@ubuntu:~$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1ffd1f30aec9        busybox             "/bin/sh -c 'i=0; wh…"   19 seconds ago      Up 18 seconds                           simple13
ubuntu@ubuntu:~$ docker logs simple13 
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ubuntu@ubuntu:~$ docker checkpoint ls simple13
Error response from daemon: open /var/lib/docker/containers/1ffd1f30aec96e07ac7c229c581b7ccd5feb9d180602eeb663211189abc652e4/checkpoints/checkpoint1/config.json: no such file or directory

但我认为,它仍然无法正常工作。例如:

<?php
$batch = $em->getRepository('MyProject\Model\Batch')->find(1);
$q = $em->createQuery('select u from MyProject\Model\Element e WHERE e.batchId = '.$batch->getId());
$iterableResult = $q->iterate();
foreach ($iterableResult as $element) {
    // Sending email
    $result = $sendingObject->send($element);
    // Error 
    if($result === 0){
        $batch->increaseError();
    } else {
        $batch->increaseSuccess();
    }
    $em->flush(); // Executes all updates.
    $em->detach($element); // Detaches only element to keep $batch synchronized
}