Using VirtualBox or KVM, I can save the state of the guest VM, reboot the host and then resume the guest.
How can I do that if my guest is only a container and not a VM ?
1 Answers
This can be done with CRIU.
Note that it's more that it can theoretically be done, but if your containers do anything remotely complex (like, say, run systemd which uses namespaces, has a tty, etc...), it will likely fail.
The more practical answer is it can't be done with general-purpose containers at this stage. Perhaps in the future, but it's unlikely given the current development pace of CRIU.
The specific commands differ depending on whether you're using raw LXC, or the LXD management daemon.
LXC
If you're using raw LXC, you'll want the lxc-checkpoint tool. There's some examples on the CRIU wiki, and the lxc-checkpoint manpages.
Please note the CRIU wiki entry recommends you configure your containers in a special way, presumably to try to avoid the namespace and device inheritance issues:
lxc.console = none
lxc.tty = 0
lxc.cgroup.devices.deny = c 5:1 rwm
This may end up being a dealbreaker if you require these devices in your container.
To create a checkpoint:
lxc-checkpoint -s -D /path/to/checkpoint -n containername
(note -s stops the container after checkpoint creation)
To restore a checkpoint:
lxc-checkpoint -r -D /path/to/checkpoint -n containername
The checkpoint will stay around until you delete it.
LXD
If you are using a snap installation of LXD, you'll first need to enable CRIU:
snap set lxd criu.enable=true
systemctl reload snap.lxd.daemon
To stop a container statefully:
lxc stop --stateful containername
If you later lxc start without --stateless, it should resume the previous state.
You can also manually create stateful snapshots with lxc snapshot / lxc restore.
- 61,637