Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an LXC container from a local template (tar.gz)

Tags:

ubuntu

lxc

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?

like image 977
syed Avatar asked May 04 '15 04:05

syed


2 Answers

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.

like image 178
syed Avatar answered Nov 13 '22 01:11

syed


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.

like image 1
daBertl Avatar answered Nov 13 '22 00:11

daBertl