I'm trying to create an LXC container from a local tar.gz of a rootfs of another container but I could not find any option in lxc-create to do so. I can create a new container, remove its rootfs and replace that with my untared rootfs but this is too clumsy. Is there a better way to do this?
After a bit of searching I found this script which takes a tar.gz and creates an LXC container.
$ lxc-create -n test-container -t ./salt_tarball -- --network_link lxcbr0 --imgtar /root/template.tar.gz
note here that salt_tarball
is the name of the script.
Using that script @syed mentioned above needs more work (Ubuntu 16.04, LXC 2.0, still not lxd):
First you have to copy the script to the template directory and make it executable
$ cp salt_tarball /usr/share/lxc/templates/lxc-salt_tarball
$ chmod +x /usr/share/lxc/templates/lxc-salt_tarball
Be sure to add lxc- in front of the name while copying.
To create the new container using the script do
$ lxc-create -n test-container -t salt_tarball -- --network_link lxcbr0 --imgtar /root/template.tar.gz
i.e. call salt_tarball without ./ and without the lxc- added above. The option --network_link is optional.
Take care to use --numeric-owner
when creating your tar.gz from any existing container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With