3

Is it possible to export a lxc container to another machine? There are some tools like lxc-snap and lxc-clone will those help in exporting to another system? Can I copy paste the rootfs folder or is there a standard way of doing this?

Nishant
  • 773

3 Answers3

2

I do not think lxc-clone and lxc-snap are supposed to be used for moving containers to a new machine. The rationale for these commands, according to one of the LXC developers, is:

One of the obvious use cases of these snapshot clones is to support incremental development of rootfs images. Make some changes, snapshot, make some more changes, snapshot, revert…

There is no mention ever of an export to a different machine...

At the same time, I have successfully ported a Debian LXC from a Debian machine to an Arch Linux machine, by first creating a Debian LXC container, without any customization, then by copying over to the new machine the config, fstab, lxcname.log files and the rootfs directory. You may try it, like I did, but ... YMMV.

MariusMatutiae
  • 48,517
  • 12
  • 86
  • 136
1

I run lxc containers on btrfs volumes so I can snapshot them easily with btrfs sub snap

These can be moved to a remote btrfs filesystem more quickly than with rsync using:

btrfs send /my/snapshot | ssh user@host.com "btrfs receive /my/destination"

btrfs is intelligent with snapshots & does not include virtual filesystems [proc run sys]. Transfering incremental snapshots are also possible.

When moving snapshots to a non btrfs filesystem:

  • Mount the remote destination as an sshfs filesystem & cd to the mount
  • Stop the container & create a tar.xz archive of the container
0

You can actually just copy the filesystem and make the relevant changes as mentioned in the above post to make everything work fine. Initially I did that and made it working.

I always have problems with NAT in LXC Containers, so if you are a light weight user, you can also just chroot into the system. Currently I use lxc-templates to create a copy of my desired OS and then chroot into that system to do my stuff. I don't need a virtualization in my use case. The idea is just simple (not in terms of implementation) that it can be ported easily.

Nishant
  • 773