Move LXC container to new VM

Create snapshot on your current VM

lxc_snapshot_publish_export.sh
lxc snapshot container_name snapshot_name

Validate created snapshot by checking the snapshots list displayed with:

lxc_info_snapshot.sh
lxc info container_name 

In case you have not named your snapshot, look for the most recent creation date. It might have a default name like snap1.

Create an image from the snapshot

lxc_publish_image.sh
lxc publish container_name/snapshot_name --alias="image_alias" description="image_description"

Verify your created image by checking the image list displayed with:

example.sh
lxc image info image_alias

Export the created image to an archive in your current path

lxc_image_export.sh
lxc image export image_alias image_archive_name

Send the file to your new VM

Make sure, that you can establish an SSH connection to your new VM from your old VM, e.g. by a VPN or Wireguard connection. Use scp to copy the image like so:

example.sh
scp ./image_archive_name.tar.gz usera@host:/home/user

Import image and launch new container on your new VM

Make sure lxc and lxd are installed on your new VM and then import the image like so:

lxc_image_import_launch.sh
lxc image import image_archive_name.tar.gz --alias image_alias_on_new_vm

Make sure the imported image appears in the list on your new VM.

example.sh
lxc image list

Then launch a new container from the image with:

example.sh
lxc launch image_alias_on_new_vm container_name

Check out similar posts by category: Container, LXC