Setting Up Your First LXC container (to clone from)

Published on:

Q: Why should I? Why not use a lxc template instead?

A: Because you’ll have to download the base packages every time. Then you’ll have to install other packages that aren’t in the base template (like wget and git).

Q: Why install puppet after I have the new container running?

A: Because puppet makes life better.

Q: Can’t you just modify the lxc template to do this instead of cloning a container all the time?

A: Yes, you could modify the lxc template to do some or all of these things. But that requires modifying the template and the templates come from the upstream vendor (Ubuntu), so I don’t want to fiddle with them.

Step 1: Install LXC

Use my Uninspiring and Un-Parameterized LXC puppet class to install LXC, set up DNS, and install lxc-templates… Or do it by hand.

Note: The puppet class assumes you *already* have a directory owned by root named ‘/home/lxc’. It’s in the in the repo. Someday, I might parameterize it. But not today.

Step 2: Create the New Container

I’m using the name “ubuntu1204-template.” It will take a while to download all the base packages.

sudo lxc-create -n ubuntu1204-template -t ubuntu

Step 3: Install missing software

Start the thing and connect to it. If you used my uninspiring puppet module to install lxc for you, just ssh to it. Otherwise, use lxc-console -d ubuntu1204-template to connect to it.

sudo lxc-start -n ubuntu1204-template
ssh ubuntu1204-template.lxc

Install wget, git, and puppet.

sudo apt-get install wget
sudo apt-get install git

If you prefer the puppet that’s packaged with Ubuntu, just useĀ apt-get install puppet. Last time I checked, it was puppet 2.7. Personally, I prefer puppet 3.2 from puppet labs:

sudo dpkg -i puppetlabs-release-precise.deb
sudo apt-get update
sudo apt-get install puppet

Step 4: Setup User Access & Puppet

Set up your user. If you’re like me, you’ll quickly get annoyed logging in as ubuntu on your lxc systems.

  1. Add your new user.
  2. Give him sudo access.
  3. Change the password for the ubuntu user to something better or delete the user altogether.

Yes, you could do this step with puppet. Just git clone your puppet repo (you do have a puppet repo, right?) and set up the node just like you would any other.

Step 5: Enjoy

Enjoy your new cloneable lxc template machine. Get it up to your personal “baseline”, but don’t use it for actual work or anything. Keep it shut down. Just clone it whenever you need a new system, but you don’t want to star from scratch.

sudo lxc-clone -o ubuntu1204-template -n new-system-name

Related Posts: {.related_post_title}

  • No Related Posts