In this lesson, you will learn how to freeze a running container's entire execution state—including its memory, CPU registers, and filesystem—to disk so it can be resumed exactly where it left off.
Beyond Filesystem Snapshots
While tools like OverlayFS allow us to track changes to the filesystem, they do not capture the "live" state of a process. If a process is performing a complex calculation or holding a TCP connection, simply snapshotting the filesystem layers will leave those volatile states behind. Checkpointing bridges this gap by dumping the process memory (the RAM contents mapped to the container) and the kernel state associated with the container's namespaces into a set of image files.
The Mechanism: CRIU
The primary technology enabling this is CRIU (Checkpoint/Restore In Userspace). When you initiate a checkpoint, the Linux kernel works with CRIU to:
- Freeze the processes within the container (stopping all execution).
- Dump the memory pages, register states, and file descriptors to a directory.
- Persist the current state of the filesystem layers (often handled via OverlayFS snapshots) to ensure the disk matches the memory state.
To restore, you simply point the runtime back at that directory. The kernel reconstructs the process memory, re-opens the file descriptors, and resumes execution as if nothing happened.
Practical Illustration
If you were using a container runtime supporting this feature, the workflow often looks like this:
# Checkpoint the container named 'web-app' into a directory
container-cli checkpoint web-app --image-path /tmp/web-app-checkpoint
# Restore the container from that same directory
container-cli restore web-app --image-path /tmp/web-app-checkpoint
This is not a reboot; it is a "pause-and-clone" operation. Because this captures memory, you must ensure the host environment remains consistent—specifically regarding the namespaces the container belongs to. If a container holds a lock on a shared resource outside its namespace, restoring it on a different host may cause the process to crash or hang due to resource mismatch.
Key Takeaway: Checkpointing captures the volatile memory state of a process in addition to its filesystem, allowing for near-instant restoration of a container's precise operational state.