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?

Edit: I ended chrooting into the /var/lib/lxc/centos folder and getting things done as that was sufficient for my use case. However make sure that you chroot according to the host system architecture i.e use linux32 chroot if the host is a 64 bit machine but your installation is 32 bit.

Nishant
  • 20,354
  • 18
  • 69
  • 101

2 Answers2

4

Did you try:

Turning a container into an image

The easiest way by far to build an image with LXD is to just turn a container into an image.

This can be done with:

lxc launch ubuntu:14.04 my-container
lxc exec my-container bash
<do whatever change you want>
lxc publish my-container --alias my-new-image
You can even turn a past container snapshot into a new image:

lxc publish my-container/some-snapshot --alias some-image

From https://insights.ubuntu.com/2016/04/01/lxd-2-0-image-management-512/

xliiv
  • 5,399
  • 5
  • 29
  • 35
  • Now while the OP didn't indicate it, the use of the tool `lxc-clone` indicates use of LXC 1.x, whereas your answer is for LXC 2.x. – 0xC0000022L Nov 27 '17 at 15:47
2

the default container location is: /var/lib/lxc/cn_name

You can lxc-stop the container then copy the cn_name contents to the same location in the new machine using typical tools such as scp, rsync etc.

You can tar up the entire cn_name directory also then untar on the new machine in the same directory

Just remember whatever you do ... preserver owner etc attributes for files & directories you copy so they are still runnable on the new system.

bmullan
  • 364
  • 2
  • 6
  • Of course with LXD/LXC you can use CRIU and live migration. There might be a few caveats - check. LXC 2.0 and LXD 1.0 I believe are both scheduled for release around Mid-to-Late January 2016... LXC with LXD uses a somewhat different (but really simplified) cli command syntax but lets you orchestrate/manage LXC containers on both local/remote Hosts really easy. see - www.linuxcontainers.org – bmullan Jan 03 '16 at 14:00