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?

  • 1
    I thought this is what publish is for. Then you can import it on another machine... – jsejcksn Apr 25 '16 at 7:50
  • 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 Apr 25 '16 at 13:11
  • 1
    linuxcontainers.org/lxd/try-it has a basic tutorial on publishing and importing, and you can find info to your heart's content at insights.ubuntu.com/2016/04/01/lxd-2-0-image-management-512 – jsejcksn Apr 25 '16 at 14:07
  • 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 Apr 25 '16 at 14:34
  • 1
    LXC/D 2.0 is a big step forward! – jsejcksn Apr 25 '16 at 15:01

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.

| improve this answer | |
  • 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 Jul 5 '15 at 14:25

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
| improve this answer | |

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.