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?
3 Answers
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.
-
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 :)– NishantCommented Jul 5, 2015 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 [email protected] "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
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.
publish
is for. Then you can import it on another machine...chrooting
etc which I have provided as an alternate option.