Changes

4,356 bytes added ,  20:30, 12 September 2014
no edit summary
Line 148: Line 148:  
$
 
$
 
</pre>
 
</pre>
 +
 +
== Help Script ==
 +
 +
As seen in the above examples, the CRIU command line for checkpointing and
 +
restoring a Docker container is pretty long.  For restore, there is also
 +
an additional step to set up the root filesystem before invoking CRIU.
 +
 +
To automate the C/R process, there is a helper script in the contrib
 +
subdirectory of CRIU sources, called docker_cr.sh.  In addition to
 +
invoking CRIU, this helper script sets up the root filesystem for AUFS,
 +
UnionFS, and VFS for restore.
 +
 +
With docker_cr.sh, all you have to provide is the container ID.
 +
If you don't specify a container ID, docker_cr.sh will list all running
 +
containers and prompt you to choose one.  Also, as shown in the help
 +
output below, by setting the appropriate environment variable, it's
 +
possible to tell docker_cr.sh which Docker and CRIU binaries to use,
 +
where Docker's home directory is, and where CRIU should save and look
 +
for its image files.
 +
 +
<pre>
 +
# docker_cr.sh --help
 +
Usage:
 +
docker_cr.sh -c|-r [-hv] [<container_id>]
 +
-c, --checkpoint checkpoint container
 +
-h, --help print help message
 +
-r, --restore restore container
 +
-v, --verbose enable verbose mode
 +
 +
Environment:
 +
DOCKER_HOME (default /var/lib/docker)
 +
CRIU_IMG_DIR (default /var/lib/docker/criu_img)
 +
DOCKER_BINARY (default docker)
 +
CRIU_BINARY (default criu)
 +
</pre>
 +
 +
Below is an example to checkpoint and restore Docker container 4397:
 +
 +
<pre>
 +
# docker_cr.sh -c 4397
 +
dump successful
 +
# docker_cr.sh -r 4397
 +
restore successful
 +
</pre>
 +
 +
Optionally, you can specify -v to see the commands that docker_cr.sh
 +
executes.  For example:
 +
 +
<pre>
 +
# docker_cr.sh -c -v 40d3
 +
docker binary: docker
 +
criu binary: criu
 +
image directory: /var/lib/docker/criu_img/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
container root directory: /var/lib/docker/aufs/mnt/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
 +
criu dump -v4 -D /var/lib/docker/criu_img/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf -o dump.log --manage-cgroups --evasive-devices --ext-mount-map /etc/resolv.conf:/etc/resolv.conf --ext-mount-map /etc/hosts:/etc/hosts --ext-mount-map /etc/hostname:/etc/hostname --ext-mount-map /.dockerinit:/.dockerinit -t 5991 --root /var/lib/docker/aufs/mnt/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
 +
dump successful
 +
(00.020827) Dumping finished successfully
 +
 +
# docker_cr.sh -r -v 40d3
 +
docker binary: docker
 +
criu binary: criu
 +
image directory: /var/lib/docker/criu_img/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
container root directory: /var/lib/docker/aufs/mnt/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
 +
mount -t aufs -o
 +
/var/lib/docker/aufs/diff/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
/var/lib/docker/aufs/diff/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf-init
 +
/var/lib/docker/aufs/diff/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721
 +
/var/lib/docker/aufs/diff/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16
 +
/var/lib/docker/aufs/diff/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229
 +
/var/lib/docker/aufs/diff/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
 +
none
 +
/var/lib/docker/aufs/mnt/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf
 +
 +
criu restore -v4 -D /var/lib/docker/criu_img/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf -o restore.log --manage-cgroups --evasive-devices --ext-mount-map /etc/resolv.conf:/var/lib/docker/containers/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf/resolv.conf --ext-mount-map /etc/hosts:/var/lib/docker/containers/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf/hosts --ext-mount-map /etc/hostname:/var/lib/docker/containers/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf/hostname --ext-mount-map /.dockerinit:/var/lib/docker/init/dockerinit-1.0.0 -d --root /var/lib/docker/aufs/mnt/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf --pidfile /var/lib/docker/criu_img/40d363f564e00a2f893579fa012a200e475dcf8df47f2a22b7dd0860ffc3d7bf/restore.pid
 +
 +
restore successful
 +
(00.408807) Restore finished successfully. Resuming tasks.
 +
 +
root      6206    1  1 10:49 ?        00:00:00 /bin/sh -c i=0; while true; do echo $i >> /foo; i=$(expr $i + 1); sleep 3; done
 +
</pre>
 +
    
[[Category:HOWTO]]
 
[[Category:HOWTO]]
26

edits