gVisor has the ability to checkpoint a process, save its current state in a state file, and restore into a new container using the state file.
Checkpoint/restore functionality is currently available via raw runsc
commands. To use the checkpoint command, first run a container.
runsc run <container id>
To checkpoint the container, the --image-path
flag must be provided. This is
the directory path within which the checkpoint related files will be created.
All necessary directories will be created if they do not yet exist.
Note: Two checkpoints cannot be saved to the same directory; every image-path provided must be unique.
runsc checkpoint --image-path=<path> <container id>
There is also an optional --leave-running
flag that allows the container to
continue to run after the checkpoint has been made. (By default, containers stop
their processes after committing a checkpoint.)
Note: All top-level runsc flags needed when calling run must be provided to checkpoint if
--leave-running
is used.
Note:
--leave-running
functions by causing an immediate restore so the container, although will maintain its given container id, may have a different process id.
runsc checkpoint --image-path=<path> --leave-running <container id>
To restore, provide the image path to the directory containing all the files created during the checkpoint. Because containers stop by default after checkpointing, restore needs to happen in a new container (restore is a command which parallels start).
runsc create <container id>
runsc restore --image-path=<path> <container id>
Note: All top-level runsc flags needed when calling run must be provided to
restore
.
Run a container:
docker run [options] --runtime=runsc --name=<container-name> <image>
Checkpoint the container:
docker checkpoint create <container-name> <checkpoint-name>
Restore into the same container:
docker start --checkpoint <checkpoint-name> <container-name>
--leave-running
flag. This issue is fixed in newer releases.--checkpoint-dir
flag but this will be required when restoring from a
checkpoint made in another container.