How do I export a lxc container?

3

1

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

Posted 2015-07-05T08:11:07.940

Reputation: 555

1I thought this is what publish is for. Then you can import it on another machine... – jsejcksn – 2016-04-25T07:50:17.077

Haven't used that. Simple copy paste works usually with LXC. It abstracts an OS as a folder so its as easy as copy paste along with a bunch of config files. – Nishant – 2016-04-25T13:11:58.320

1https://linuxcontainers.org/lxd/try-it/ has a basic tutorial on publishing and importing, and you can find info to your heart's content at https://insights.ubuntu.com/2016/04/01/lxd-2-0-image-management-512/ – jsejcksn – 2016-04-25T14:07:27.060

Thats an awesome link! Will go through it. Back in the days I had this problem, there was no resources I could find. However it helped me learn some new stuff like chrooting etc which I have provided as an alternate option. – Nishant – 2016-04-25T14:34:34.747

1LXC/D 2.0 is a big step forward! – jsejcksn – 2016-04-25T15:01:08.380

Answers

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

Posted 2015-07-05T08:11:07.940

Reputation: 41 321

Awesome! I had the same thought. I was thinking of copying over the rootfs as well but wanted to see if a tool exists. Interesting to see config fstab and lxcname.log in that list of files to be copied. I will select this as the best answer unless someone suggest a tool which apparently doesn't exist atm :) – Nishant – 2015-07-05T14:25:55.047

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

Stuart Cardall

Posted 2015-07-05T08:11:07.940

Reputation: 236

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

Posted 2015-07-05T08:11:07.940

Reputation: 555