Is it possible to create an LXC container that you maintain only for the purpose of copying as a template? If so, how does one properly copy an LXC container?
Is it possible to create an LXC container that you maintain only for the purpose of copying as a template? If so, how does one properly copy an LXC container?
Yes, an LXC container is some config files and a directory within the whole server. If you copy this directory and config files and adjust the parameters you can use it as a template. Just tar it and untar it to the new machine's directory.
This can be easily obtained using BTRFS filesystem in combination with snapshots.
The template filesystem must reside in a subvolume on a btrfs filesystem, say
After which you can populate it.
To create the snapshot:
Afterwards remove the snapshot with:
Advantages are that:
Further on, if you want to provide your container with some writable private directories on top of a read-only template filesystem you could use mount -o bind from within the container
I also use a main template for all my containers.
If you are using Ubuntu 14.04, lxc-clone is your friend to create new container based off a template.