Cloud Native 5 min read

How to Use Docker Checkpoint & CRIU for Live Container Migration

This guide walks you through enabling Docker's experimental mode, installing CRIU, building a simple Node container, creating checkpoints, and restoring containers both on the same host and on a different host, highlighting the prerequisites and limitations of live migration.

Node Underground
Node Underground
Node Underground
How to Use Docker Checkpoint & CRIU for Live Container Migration

Prerequisites

Docker manages container processes; CRIU is integrated in Docker's experimental mode since Docker 1.13. Enable experimental mode by adding {"experimental": true} to /etc/docker/daemon.json and restarting Docker.

$ echo '{"experimental": true}' >> /etc/docker/daemon.json
$ systemctl restart docker

Install CRIU version 2.0 or higher and upgrade the Linux kernel to version 4.3 or newer. Verify the setup with criu check --all and look for the “Looks good” message.

$ criu check --all
Warn (criu/cr-check.c:680): Dirty tracking is OFF. Memory snapshot will not work.
Looks good but some kernel features are missing ...

Build a Sample Docker Image

Create a simple Node program that prints an incrementing number every second.

FROM node
ADD ./app /app
WORKDIR /app
CMD ["node", "index"]
let idx = 0;
setInterval(() => {
  console.log(idx++);
}, 1000);

Build the image:

docker build . -t looper-image

Checkpoint

Run the container and create a checkpoint.

docker run -d --name looper looper-image
docker logs looper   # shows 0 1 2 …
docker checkpoint create looper cp1

After checkpointing the container stops; no logs are produced.

Restore

Restore the same container from the checkpoint: docker start --checkpoint cp1 looper Logs resume from the saved state.

Restore to a New Container or Host

Export the checkpoint directory, copy it to another host, create a new container, place the checkpoint files, and start with --checkpoint=cp1. Logs continue from the saved point.

tar -cvf /root/cp1.tar.gz ./cp1/
scp cp1.tar.gz other-host:/tmp
docker create --name looper-clone looper-image
# extract into /var/lib/docker/containers/<id>/checkpoints
docker start --checkpoint=cp1 looper-clone

Cross‑host migration requires identical environments; CRIU remains experimental for production use.

cloud-nativeLinux kernelCheckpointContainer Migrationcriu
Node Underground
Written by

Node Underground

No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.