Note
The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
LXD/Container Migration
Jump to navigation
Jump to search
The idea is – take a snapshot of the container before starting an upgrade. But to get databases in a sane state, I do:
- stop the container
- take a snapshot
- optional: start the container again so it is "up" (you can't do this most containers, ones you expect to change, like bugs, code, forums, maybe www. But for read-only services, it is a trick to keep the container "up" during a migration)
- create an image from the snapshot using "lxd publish --compression pigz containername/2022-10-17 --alias containnername"
- with two lxd hosts linked, you can then launch the image on the other container – before it starts, stop the original running container from step #3 if you did this to avoid IP conflict.
- now ensure the new container is working as expected.
- delete old container on original host (will also delete snapshots), or you can delete new container and try again if there is a problem.
This might seem like a pretty complicated method but I have found it to be good for lxd for some technical reasons:
- One, is that the snapshot works around an issue: "lxc move/copy" expects the EXACT profiles to exist on both lxd hosts, but our profile names are often different. lxd will often get "stuck" and "lxc move/copy" will not work for this reason. By creating an image, we free ourselves from this problem. We will re-apply the correct profiles for the new host using -p option ourselves, and make any other necessary config changes if required.
- Second, pigz compression (could also use lzo) dramatically speeds up creation of the container image (gz single-thread is default)
- Third, we have a snapshot if there is a problem, and we can even go back to the original container if there is a major problem with our snapshot (since it is just stopped on orighost)
Here are relevant commands:
Origin host
root # lxc stop foo root # lxc snapshot foo 2022-10-26 root # lxc start foo root # lxc publish foo/2022-10-26 --compression pigz --alias foo # <-- image will also be named "foo"
On second lxd server "linked" to first
root # lxc launch orighost:foo foo -p default -p local_correct_profile1 -p local_correct_profile2
On first lxd server before this command actually starts container (this image creation from remote can take some time...)
Origin host
root # lxc stop foo
if new container is OK:
root # lxc delete foo
On second lxd server "linked" to first
if new container is OK:
root # lxc image delete foo