Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 22. Creating and restoring container checkpoints
Checkpoint/Restore In Userspace (CRIU) is a software that enables you to set a checkpoint on a running container or an individual application and store its state to disk. You can use data saved to restore the container after a reboot at the same point in time it was checkpointed.
The kernel does not support pre-copy checkpointing on AArch64.
22.1. Creating and restoring a container checkpoint locally Copier lienLien copié sur presse-papiers!
This example is based on a Python based web server which returns a single integer which is incremented after each request.
Prerequisites
-
The
container-toolsmodule is installed.
Procedure
Create a Python based server:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a container with the following definition:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The container is based on the Universal Base Image (UBI 8) and uses a Python based server.
Build the container:
podman build . --tag counter
# podman build . --tag counterCopy to Clipboard Copied! Toggle word wrap Toggle overflow Files
counter.pyandContainerfileare the input for the container build process (podman build). The built image is stored locally and tagged with the tagcounter.Start the container as root:
podman run --name criu-test --detach counter
# podman run --name criu-test --detach counterCopy to Clipboard Copied! Toggle word wrap Toggle overflow To list all running containers, enter:
podman ps
# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e4f82fd84d48 localhost/counter:latest 5 seconds ago Up 4 seconds ago criu-testCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display IP address of the container:
podman inspect criu-test --format "{{.NetworkSettings.IPAddress}}"# podman inspect criu-test --format "{{.NetworkSettings.IPAddress}}" 10.88.0.247Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send requests to the container:
curl 10.88.0.247:8088 curl 10.88.0.247:8088
# curl 10.88.0.247:8088 0 # curl 10.88.0.247:8088 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a checkpoint for the container:
podman container checkpoint criu-test
# podman container checkpoint criu-testCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Reboot the system.
Restore the container:
podman container restore --keep criu-test
# podman container restore --keep criu-testCopy to Clipboard Copied! Toggle word wrap Toggle overflow Send requests to the container:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The result now does not start at
0again, but continues at the previous value.
This way you can easily save the complete container state through a reboot.
22.2. Reducing startup time using container restore Copier lienLien copié sur presse-papiers!
You can use container migration to reduce startup time of containers which require a certain time to initialize. Using a checkpoint, you can restore the container multiple times on the same host or on different hosts. This example is based on the container from the Creating and restoring a container checkpoint locally.
Prerequisites
-
The
container-toolsmodule is installed.
Procedure
Create a checkpoint of the container, and export the checkpoint image to a
tar.gzfile:podman container checkpoint criu-test --export /tmp/chkpt.tar.gz
# podman container checkpoint criu-test --export /tmp/chkpt.tar.gzCopy to Clipboard Copied! Toggle word wrap Toggle overflow Restore the container from the
tar.gzfile:podman container restore --import /tmp/chkpt.tar.gz --name counter1 podman container restore --import /tmp/chkpt.tar.gz --name counter2 podman container restore --import /tmp/chkpt.tar.gz --name counter3
# podman container restore --import /tmp/chkpt.tar.gz --name counter1 # podman container restore --import /tmp/chkpt.tar.gz --name counter2 # podman container restore --import /tmp/chkpt.tar.gz --name counter3Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
--name(-n) option specifies a new name for containers restored from the exported checkpoint.Display ID and name of each container:
podman ps -a --format "{{.ID}} {{.Names}}"# podman ps -a --format "{{.ID}} {{.Names}}" a8b2e50d463c counter3 faabc5c27362 counter2 2ce648af11e5 counter1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display IP address of each container:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send requests to each container:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note, that the result is
4in all cases, because you are working with different containers restored from the same checkpoint.
Using this approach, you can quickly start up stateful replicas of the initially checkpointed container.
22.3. Migrating containers among systems Copier lienLien copié sur presse-papiers!
You can migrate the running containers from one system to another, without losing the state of the applications running in the container. This example is based on the container from the Creating and restoring a container checkpoint locally section tagged with counter.
Migrating containers among systems with the podman container checkpoint and podman container restore commands is supported only when the configurations of the systems match completely, as shown below:
- Podman version
- OCI runtime (runc/crun)
- Network stack (CNI/Netavark)
- Cgroups version
- kernel version
- CPU features
You can migrate to a CPU with more features, but not to a CPU which does not have a certain feature that you are using. The low-level tool doing the checkpointing (CRIU) has the possibility to check for CPU feature compatibility: https://criu.org/Cpuinfo.
Prerequisites
-
The
container-toolsmodule is installed. The following steps are not necessary if the container is pushed to a registry as Podman will automatically download the container from a registry if it is not available locally. This example does not use a registry, you have to export previously built and tagged container (see Creating and restoring a container checkpoint locally).
Export previously built container:
podman save --output counter.tar counter
# podman save --output counter.tar counterCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy exported container image to the destination system (
other_host):scp counter.tar other_host:
# scp counter.tar other_host:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import exported container on the destination system:
ssh other_host podman load --input counter.tar
# ssh other_host podman load --input counter.tarCopy to Clipboard Copied! Toggle word wrap Toggle overflow Now the destination system of this container migration has the same container image stored in its local container storage.
Procedure
Start the container as root:
podman run --name criu-test --detach counter
# podman run --name criu-test --detach counterCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display IP address of the container:
podman inspect criu-test --format "{{.NetworkSettings.IPAddress}}"# podman inspect criu-test --format "{{.NetworkSettings.IPAddress}}" 10.88.0.247Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send requests to the container:
curl 10.88.0.247:8080 curl 10.88.0.247:8080
# curl 10.88.0.247:8080 0 # curl 10.88.0.247:8080 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a checkpoint of the container, and export the checkpoint image to a
tar.gzfile:podman container checkpoint criu-test --export /tmp/chkpt.tar.gz
# podman container checkpoint criu-test --export /tmp/chkpt.tar.gzCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the checkpoint archive to the destination host:
scp /tmp/chkpt.tar.gz other_host:/tmp/
# scp /tmp/chkpt.tar.gz other_host:/tmp/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Restore the checkpoint on the destination host (
other_host):podman container restore --import /tmp/chkpt.tar.gz
# podman container restore --import /tmp/chkpt.tar.gzCopy to Clipboard Copied! Toggle word wrap Toggle overflow Send a request to the container on the destination host (
other_host):*curl 10.88.0.247:8080*
# *curl 10.88.0.247:8080* 2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
As a result, the stateful container has been migrated from one system to another without losing its state.