2023-01-06 13:04:05 -05:00
|
|
|
# checkpoint
|
|
|
|
|
|
|
|
<!---MARKER_GEN_START-->
|
|
|
|
Manage checkpoints
|
|
|
|
|
|
|
|
### Subcommands
|
|
|
|
|
|
|
|
| Name | Description |
|
|
|
|
|:---------------------------------|:---------------------------------------------|
|
|
|
|
| [`create`](checkpoint_create.md) | Create a checkpoint from a running container |
|
|
|
|
| [`ls`](checkpoint_ls.md) | List checkpoints for a container |
|
|
|
|
| [`rm`](checkpoint_rm.md) | Remove a checkpoint |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!---MARKER_GEN_END-->
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
## Description
|
|
|
|
|
|
|
|
Checkpoint and Restore is an experimental feature that allows you to freeze a running
|
2023-12-13 09:16:56 -05:00
|
|
|
container by specifying a checkpoint, which turns the container state into a collection of files
|
2016-05-12 10:52:00 -04:00
|
|
|
on disk. Later, the container can be restored from the point it was frozen.
|
|
|
|
|
2021-10-14 18:04:36 -04:00
|
|
|
This is accomplished using a tool called [CRIU](https://criu.org), which is an
|
2016-05-12 10:52:00 -04:00
|
|
|
external dependency of this feature. A good overview of the history of
|
|
|
|
checkpoint and restore in Docker is available in this
|
2018-12-28 19:39:54 -05:00
|
|
|
[Kubernetes blog post](https://kubernetes.io/blog/2015/07/how-did-quake-demo-from-dockercon-work/).
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
### Installing CRIU
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
If you use a Debian system, you can add the CRIU PPA and install with `apt-get`
|
2023-12-13 09:16:56 -05:00
|
|
|
[from the CRIU launchpad](https://launchpad.net/~criu/+archive/ubuntu/ppa).
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
Alternatively, you can [build CRIU from source](https://criu.org/Installation).
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
You need at least version 2.0 of CRIU to run checkpoint and restore in Docker.
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
### Use cases for checkpoint and restore
|
2016-05-12 10:52:00 -04:00
|
|
|
|
|
|
|
This feature is currently focused on single-host use cases for checkpoint and
|
|
|
|
restore. Here are a few:
|
|
|
|
|
|
|
|
- Restarting the host machine without stopping/starting containers
|
|
|
|
- Speeding up the start time of slow start applications
|
|
|
|
- "Rewinding" processes to an earlier point in time
|
|
|
|
- "Forensic debugging" of running processes
|
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
Another primary use case of checkpoint and restore outside of Docker is the live
|
2016-05-12 10:52:00 -04:00
|
|
|
migration of a server from one machine to another. This is possible with the
|
|
|
|
current implementation, but not currently a priority (and so the workflow is
|
|
|
|
not optimized for the task).
|
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
### Using checkpoint and restore
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2016-09-12 00:09:54 -04:00
|
|
|
A new top level command `docker checkpoint` is introduced, with three subcommands:
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
- `docker checkpoint create` (creates a new checkpoint)
|
|
|
|
- `docker checkpoint ls` (lists existing checkpoints)
|
|
|
|
- `docker checkpoint rm` (deletes an existing checkpoint)
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
Additionally, a `--checkpoint` flag is added to the `docker container start` command.
|
|
|
|
|
|
|
|
The options for `docker checkpoint create`:
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
```console
|
|
|
|
Usage: docker checkpoint create [OPTIONS] CONTAINER CHECKPOINT
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
Create a checkpoint from a running container
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
--leave-running=false Leave the container running after checkpoint
|
|
|
|
--checkpoint-dir Use a custom checkpoint storage directory
|
|
|
|
```
|
2016-05-12 10:52:00 -04:00
|
|
|
|
|
|
|
And to restore a container:
|
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
```console
|
|
|
|
Usage: docker start --checkpoint CHECKPOINT_ID [OTHER OPTIONS] CONTAINER
|
|
|
|
```
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
Example of using checkpoint and restore on a container:
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
```console
|
|
|
|
$ docker run --security-opt=seccomp:unconfined --name cr -d busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'
|
|
|
|
abc0123
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
$ docker checkpoint create cr checkpoint1
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
# <later>
|
|
|
|
$ docker start --checkpoint checkpoint1 cr
|
|
|
|
abc0123
|
|
|
|
```
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-10-11 10:18:14 -04:00
|
|
|
This process just logs an incrementing counter to stdout. If you run `docker logs`
|
2023-12-13 09:16:56 -05:00
|
|
|
in-between running/checkpoint/restoring, you should see that the counter
|
|
|
|
increases while the process is running, stops while it's frozen, and
|
2016-05-12 10:52:00 -04:00
|
|
|
resumes from the point it left off once you restore.
|
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
### Known limitations
|
2016-09-13 01:14:41 -04:00
|
|
|
|
2023-12-13 09:16:56 -05:00
|
|
|
`seccomp` is only supported by CRIU in very up-to-date kernels.
|
2016-09-13 01:14:41 -04:00
|
|
|
|
2023-12-13 09:16:56 -05:00
|
|
|
External terminals (i.e. `docker run -t ..`) aren't supported.
|
2021-10-07 03:13:21 -04:00
|
|
|
If you try to create a checkpoint for a container with an external terminal,
|
2023-12-13 09:16:56 -05:00
|
|
|
it fails:
|
2016-09-13 01:14:41 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
```console
|
|
|
|
$ docker checkpoint create cr checkpoint1
|
|
|
|
Error response from daemon: Cannot checkpoint container c1: rpc error: code = 2 desc = exit status 1: "criu failed: type NOTIFY errno 0\nlog file: /var/lib/docker/containers/eb62ebdbf237ce1a8736d2ae3c7d88601fc0a50235b0ba767b559a1f3c5a600b/checkpoints/checkpoint1/criu.work/dump.log\n"
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2021-08-23 11:41:23 -04:00
|
|
|
$ cat /var/lib/docker/containers/eb62ebdbf237ce1a8736d2ae3c7d88601fc0a50235b0ba767b559a1f3c5a600b/checkpoints/checkpoint1/criu.work/dump.log
|
|
|
|
Error (mount.c:740): mnt: 126:./dev/console doesn't have a proper root mount
|
|
|
|
```
|